multiple NICs and routes
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 ================================
Jason Joines wrote:
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 ================================
Turns out there were a lot of ways to do this. The file /etc/sysconfig/network/ifcfg.template shows a few variables you can use and tells you to look at the man page of ifup and the files /etc/sysconfig/network/config,dhcp,wireless for more. I somehow overlooked what I need in the man page and didn't find it in the files but read the actual /sbin/ifup script and found the variable POST_UP_SCRIPT. I set it to POST_UP_SCRIPT='scripts/postup-lan1' in the config file for lan1, /etc/sysconfig/network/ifcfg-eth-id-mymacaddress where the contents of postup-lan1 are: # cat scripts/postup-lan1 ifconfig | grep '^lan1' && route del -net 139.78.88.0 netmask 255.255.252.0 metric 0 dev lan1 ifconfig | grep '^lan1' && route add -net 139.78.88.0 netmask 255.255.252.0 metric 5 dev lan1 All is working as desired now. Jason ===========
Jason Joines wrote:
Jason Joines wrote:
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 ================================
Turns out there were a lot of ways to do this. The file /etc/sysconfig/network/ifcfg.template shows a few variables you can use and tells you to look at the man page of ifup and the files /etc/sysconfig/network/config,dhcp,wireless for more. I somehow overlooked what I need in the man page and didn't find it in the files but read the actual /sbin/ifup script and found the variable POST_UP_SCRIPT. I set it to POST_UP_SCRIPT='scripts/postup-lan1' in the config file for lan1, /etc/sysconfig/network/ifcfg-eth-id-mymacaddress where the contents of postup-lan1 are:
# cat scripts/postup-lan1 ifconfig | grep '^lan1' && route del -net 139.78.88.0 netmask 255.255.252.0 metric 0 dev lan1 ifconfig | grep '^lan1' && route add -net 139.78.88.0 netmask 255.255.252.0 metric 5 dev lan1
All is working as desired now.
Jason ===========
Woops. That was the content of a script I tried in /etc/sysconfig/network/ifup.d before finding out you could use POST_UP_SCRIPT on a specific NIC. That one just looks like this: # cat scripts/postup-lan1 route add -net 139.78.88.0 netmask 255.255.252.0 metric 5 dev lan1 route del -net 139.78.88.0 netmask 255.255.252.0 metric 0 dev lan1 Jason ===========
participants (2)
-
CBA Computer Support
-
Jason Joines