multiple NICs and routes

Jason Joines support
Wed Sep 14 12:04:22 PDT 2005


   I have SuSE linux 9.3 with two NIC's in it.  Which was picked as eth0 
and which as eth1 changed sometimes and I needed them to stay the same.  
This was solved by setting their names to lan0 and lan1 using the 
PERSISTENT_NAME option in their configuration files.  However, both NICs 
are on the same subnet and I need to be able to pick which one is used 
to communicate with other hosts on the same subnet.  The routing table 
looks like this:

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use 
Iface
172.18.88.0     0.0.0.0         255.255.252.0   U     0      0        0 
lan0
172.18.88.0     0.0.0.0         255.255.252.0   U     0      0        0 
lan1
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         172.18.91.254   0.0.0.0         UG    0      0        0 
lan0

   With this routing setup, communication with other hosts on the same 
subnet sometimes goes through lan0 and sometimes through lan1.  I need 
to make sure it always goes through lan0.  I was able to solve this 
manually by changing the metric for the route through lan1 as:

# route add -net 172.18.88.0 netmask 255.255.252.0 metric 5 dev lan1
# route del -net 172.18.88.0 netmask 255.255.252.0 metric 0 dev lan1
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use 
Iface
172.18.88.0     0.0.0.0         255.255.252.0   U     0      0        0 
lan0
172.18.88.0     0.0.0.0         255.255.252.0   U     5      0        0 
lan1
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         172.18.91.254   0.0.0.0         UG    0      0        0 
lan0


   I would like to be able to make this happen automatically though.  If 
I add an entry in the routes file for lan1 with a higher metric, I get 
multiple routes out lan1, one with a 0 metric and one higher.

# cat /etc/sysconfig/network/routes
default 172.18.91.254 - lan0
172.18.88.0 - 255.255.252.0 lan1 - metric 5

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use 
Iface
172.18.88.0     0.0.0.0         255.255.252.0   U     0      0        0 
lan0
172.18.88.0     0.0.0.0         255.255.252.0   U     0      0        0 
lan1
172.18.88.0     0.0.0.0         255.255.252.0   U     5      0        0 
lan1
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         172.18.91.254   0.0.0.0         UG    0      0        0 
lan0


   I tried putting the metric 5 route in ifroute-lan1 instead of routes 
but that had no effect.  How do I automatically delete or replace the 0 
metric route out lan1?  Is there a better way to do this than what I've 
tried so far?

Thanks,

Jason Joines
================================


More information about the Linux-users mailing list