a56a5e
From aa5313ca0e17bb08dd0629c3f9385672408caceb Mon Sep 17 00:00:00 2001
a56a5e
From: Will Woods <wwoods@redhat.com>
a56a5e
Date: Thu, 28 Aug 2014 13:44:47 -0400
a56a5e
Subject: [PATCH] do 'ip route replace default' instead of 'add'
a56a5e
a56a5e
When you define the gateway for an interface, dracut sets it up with:
a56a5e
a56a5e
  ip route add default via $gw dev $netif
a56a5e
a56a5e
If a default route is already set (e.g. if you have multiple NICs), this
a56a5e
will fail with the message "RTNETLINK answers: File exists".
a56a5e
a56a5e
So, if your first NIC isn't usable as a default route
a56a5e
a56a5e
Using "ip route replace default" instead allows ifup/dhclient-script to
a56a5e
correctly change the default route to the new interface.
a56a5e
---
a56a5e
 modules.d/40network/dhclient-script.sh | 2 +-
a56a5e
 modules.d/40network/ifup.sh            | 2 +-
a56a5e
 2 files changed, 2 insertions(+), 2 deletions(-)
a56a5e
a56a5e
diff --git a/modules.d/40network/dhclient-script.sh b/modules.d/40network/dhclient-script.sh
1755ca
index ba05250d..885303a2 100755
a56a5e
--- a/modules.d/40network/dhclient-script.sh
a56a5e
+++ b/modules.d/40network/dhclient-script.sh
a56a5e
@@ -45,7 +45,7 @@ setup_interface() {
a56a5e
         valid_lft ${lease_time} preferred_lft ${lease_time} \
a56a5e
         dev $netif
a56a5e
 
a56a5e
-    [ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw
a56a5e
+    [ -n "$gw" ] && echo ip route replace default via $gw dev $netif > /tmp/net.$netif.gw
a56a5e
 
a56a5e
     [ -n "${search}${domain}" ] && echo "search $search $domain" > /tmp/net.$netif.resolv.conf
a56a5e
     if  [ -n "$namesrv" ] ; then
a56a5e
diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh
1755ca
index 43e84a2c..67b1d9f8 100755
a56a5e
--- a/modules.d/40network/ifup.sh
a56a5e
+++ b/modules.d/40network/ifup.sh
a56a5e
@@ -145,7 +145,7 @@ do_static() {
a56a5e
         ip addr add $ip/$mask ${srv:+peer $srv} brd + dev $netif
a56a5e
     fi
a56a5e
 
a56a5e
-    [ -n "$gw" ] && echo ip route add default via $gw dev $netif > /tmp/net.$netif.gw
a56a5e
+    [ -n "$gw" ] && echo ip route replace default via $gw dev $netif > /tmp/net.$netif.gw
a56a5e
     [ -n "$hostname" ] && echo "echo $hostname > /proc/sys/kernel/hostname" > /tmp/net.$netif.hostname
a56a5e
 
a56a5e
     return 0