Why might route-eth0 be ignored but route-eth1 not? Might be because eth0 is using DHCP and eth1 is statically-configured?
I have some static routes configured in
[16:20:06][root@zserver2:/etc/sysconfig/network-scripts]$ ls -al ro*
-rw-r--r-- 1 root root 104 Dec 6 15:49 route-eth0
-rw-r--r-- 1 root root 106 Dec 6 15:49 route-eth1
When I do a service network restart
the routes for eth1 are activated but NOT those for eth0.
An ifup eth0
also ignores them, but an ifup-routes eth0
is just fine. What's the best way of getting it activated?
[16:18:36][root@zserver2:/etc/sysconfig/network-scripts]$ service network restart
Shutting down interface eth0: Device state: 3 (disconnected)
[ OK ]
Shutting down interface eth1: Device state: 3 (disconnected)
[ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Active connection state: activating
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/28
state: activated
Connection activated
[ OK ]
Bringing up interface eth1: Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/29
[ OK ]
route info
[16:18:50][root@zserver2:/etc/sysconfig/network-scripts]$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.15.10 192.168.15.11 255.255.255.255 UGH 1 0 0 eth1
192.168.15.11 0.0.0.0 255.255.255.255 UH 0 0 0 eth1
192.168.15.11 192.168.15.91 255.255.255.255 UGH 1 0 0 eth1
192.168.15.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 192.168.15.1 0.0.0.0 UG 0 0 0 eth0
ifup eth0 manually
[16:19:03][root@zserver2:/etc/sysconfig/network-scripts]$ ifup eth0
Active connection state: activating
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/30
state: activated
Connection activated
route info
[16:19:35][root@zserver2:/etc/sysconfig/network-scripts]$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.15.10 192.168.15.11 255.255.255.255 UGH 1 0 0 eth1
192.168.15.11 0.0.0.0 255.255.255.255 UH 0 0 0 eth1
192.168.15.11 192.168.15.91 255.255.255.255 UGH 1 0 0 eth1
192.168.15.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 192.168.15.1 0.0.0.0 UG 0 0 0 eth0
ifup-routes eth0 manually
[16:19:56][root@zserver2:/etc/sysconfig/network-scripts]$ ./ifup-routes eth0
[16:20:00][root@zserver2:/etc/sysconfig/network-scripts]$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.15.1 192.168.15.90 255.255.255.255 UGH 5 0 0 eth0
192.168.15.10 192.168.15.11 255.255.255.255 UGH 1 0 0 eth1
192.168.15.10 192.168.15.1 255.255.255.255 UGH 5 0 0 eth0
192.168.15.11 0.0.0.0 255.255.255.255 UH 0 0 0 eth1
192.168.15.11 192.168.15.91 255.255.255.255 UGH 1 0 0 eth1
192.168.15.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 192.168.15.1 0.0.0.0 UG 0 0 0 eth0
Config files are:
ifcfg-eth0
[16:30:26][root@zserver2:/etc/sysconfig/network-scripts]$ cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
UUID=76ef8242-9e22-4a29-93f3-a142d1460c87
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
HWADDR=00:25:90:86:71:E0
PEERDNS=yes
PEERROUTES=yes
LAST_CONNECT=1386361279
ifcfg-eth1
[16:30:35][root@zserver2:/etc/sysconfig/network-scripts]$ cat ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
UUID=647f66bd-67b2-4e9a-b5a5-4280ad677b9a
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth1"
IPADDR=192.168.15.91
PREFIX=32
HWADDR=00:25:90:86:71:E1
LAST_CONNECT=1386361279
Best Answer
The problem is likely timing. Among other things, the
ifup
script does this:eth0
in an "up" statedhclient
to obtain an IP addressroute-eth0
The problem is that
ifup
doesn't wait fordhclient
to get an IP address before trying to load your static routes, and the kernel won't install a route for an interface without an IP address configured on it.If you must use DHCP, one solution is to let
dhclient
add the routes for you. Per the manpage for dhclient-script(8) from CentOS 6.5:You should be able to make this work by creating a
/etc/dhcp/dhclient-eth0-up-hooks
script containing the following: