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: 039~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7e50abfdb8ab51a2086b60635bfc3cc7f9db03df;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 0d0d8c950..50f1985b5 100755 --- a/modules.d/40network/dhclient-script.sh +++ b/modules.d/40network/dhclient-script.sh @@ -43,7 +43,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 a8377a48d..66a3ff436 100755 --- a/modules.d/40network/ifup.sh +++ b/modules.d/40network/ifup.sh @@ -143,7 +143,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