linux how to config route etc/network/interfaces?

11,321

Welcome to stackexchange. Please read this on cross-posting the same question on several stackexchange sites.

Now, to your question. The short answer: it does work. In details:

the route next after default in route printout:

192.168.32.0 192.168.32.251 255.255.255.0 UG 0 0 0 eth1

is the result of

post-up route add -net 192.168.32.0 netmask 255.255.255.0 gw 192.168.32.251 dev eth1

in your interfaces script. The second route to net 192.168.33.0/24 via gateway 192.168.33.251 is failed to add as there is no route to host 192.168.33.251 known on the eth1 interface. Either you meant to say that the route to net 192.168.33.0/24 is via gateway 192.168.32.251, or you need to add an explicit route to 192.168.33.251 according to your network configuration.

Share:
11,321

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    how to config route in etc/network/interfaces ? i want add 3 route in eth0 and eth1

    i have try to configure like this:

    auto lo
    iface lo inet loopback
    
    auto eth0
    iface eth0 inet static
            address 192.168.82.168
            network 192.168.82.0
            netmask 255.255.255.0
            broadcast 192.168.82.255
            gateway 192.168.82.251
            mtu 1500
    
    auto eth1
    iface eth1 inet static
            address 192.168.32.164
            network 192.168.32.0
            netmask 255.255.255.0
            broadcast 192.168.32.255
            mtu 1500
    post-up route add -net 192.168.32.0 netmask 255.255.255.0 gw 192.168.32.251 dev eth1
    pre-down route add -net 192.168.32.0 netmask 255.255.255.0 gw 192.168.32.251 dev eth1
    post-up route add -net 192.168.33.0 netmask 255.255.255.0 gw 192.168.33.251 dev eth1
    pre-down route add -net 192.168.33.0 netmask 255.255.255.0 gw 192.168.33.251 dev eth1
    

    but it doesn't work,i insert in command:

    #route
    

    the result print out:

     Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    default         192.168.82.251  0.0.0.0         UG    0      0        0 eth0
    192.168.32.0    192.168.32.251  255.255.255.0   UG    0      0        0 eth1
    192.168.32.0    *               255.255.255.0   U     0      0        0 eth1
    192.168.82.0    *               255.255.255.0   U     0      0        0 eth0