From: Will Woods Date: Thu, 28 Aug 2014 17:44:47 +0000 (-0400) Subject: do 'ip route replace default' instead of 'add' X-Git-Tag: RHEL-7.1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aa5313ca0e17bb08dd0629c3f9385672408caceb;p=thirdparty%2Fdracut.git do 'ip route replace default' instead of 'add' When you define the gateway for an interface, dracut sets it up with: ip route add default via $gw dev $netif If a default route is already set (e.g. if you have multiple NICs), this will fail with the message "RTNETLINK answers: File exists". So, if your first NIC isn't usable as a default route Using "ip route replace default" instead allows ifup/dhclient-script to correctly change the default route to the new interface. --- diff --git a/modules.d/40network/dhclient-script.sh b/modules.d/40network/dhclient-script.sh index ba05250de..885303a2c 100755 --- a/modules.d/40network/dhclient-script.sh +++ b/modules.d/40network/dhclient-script.sh @@ -45,7 +45,7 @@ setup_interface() { valid_lft ${lease_time} preferred_lft ${lease_time} \ dev $netif - [ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw + [ -n "$gw" ] && echo ip route replace default via $gw dev $netif > /tmp/net.$netif.gw [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf if [ -n "$namesrv" ] ; then diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh index 43e84a2c1..67b1d9f8b 100755 --- a/modules.d/40network/ifup.sh +++ b/modules.d/40network/ifup.sh @@ -145,7 +145,7 @@ do_static() { ip addr add $ip/$mask ${srv:+peer $srv} brd + dev $netif fi - [ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw + [ -n "$gw" ] && echo ip route replace default via $gw dev $netif > /tmp/net.$netif.gw [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname return 0