diff --git a/xCAT-server/lib/xcat/plugins/route.pm b/xCAT-server/lib/xcat/plugins/route.pm index 8ec31df6c..02ece1454 100644 --- a/xCAT-server/lib/xcat/plugins/route.pm +++ b/xCAT-server/lib/xcat/plugins/route.pm @@ -614,7 +614,11 @@ sub set_route { } } else { if (xCAT::Utils->isLinux()) { - $cmd="route add -net $net netmask $mask gw $gw_ip"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $cmd="route add -net $net netmask $mask dev $ifname"; + } else { + $cmd="route add -net $net netmask $mask gw $gw_ip"; + } } else { $cmd="route add -net $net -netmask $mask $gw_ip"; } @@ -987,7 +991,11 @@ sub addPersistentRoute_RH { $new_config="$ifname $net/$mask $gw_ip"; } else { - $new_config="any net $net netmask $mask gw $gw_ip $ifname\n"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $new_config="any net $net netmask $mask dev $ifname\n"; + } else { + $new_config="any net $net netmask $mask gw $gw_ip $ifname\n"; + } } if (!$hasConfiged) { push(@output, $new_config); @@ -1125,7 +1133,11 @@ sub addPersistentRoute_Debian{ } else { #ipv4 $cmd = "grep \"-net $net netmask $mask gw $gw_ip\" $conf_file"; - $route_conf = " up route add -net $net netmask $mask gw $gw_ip \n down route del -net $net netmask $mask gw $gw_ip \n"; + if ( $gw_ip == "" || $gw_ip == "0.0.0.0" ) { + $route_conf = " up route add -net $net netmask $mask dev $ifname \n down route del -net $net netmask $mask dev $ifname \n"; + } else { + $route_conf = " up route add -net $net netmask $mask gw $gw_ip \n down route del -net $net netmask $mask gw $gw_ip\n"; + } } #fine the corresponding config in the config file diff --git a/xCAT/postscripts/routeop b/xCAT/postscripts/routeop index 7260a033a..fc1c50f0e 100755 --- a/xCAT/postscripts/routeop +++ b/xCAT/postscripts/routeop @@ -240,8 +240,13 @@ add_persistent_route() echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile else - echo " up route add -net $net netmask $mask gw $gw" >> $tempfile - echo " down route del -net $net netmask $mask gw $gw" >> $tempfile + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + echo " up route add -net $net netmask $mask dev $ifname" >> $tempfile + echo " down route del -net $net netmask $mask dev $ifname" >> $tempfile + else + echo " up route add -net $net netmask $mask gw $gw" >> $tempfile + echo " down route del -net $net netmask $mask gw $gw" >> $tempfile + fi fi fi echo $LINE | grep "iface $ifname " 2>&1 1>/dev/null @@ -258,8 +263,13 @@ add_persistent_route() echo " up route -A inet6 add $net/$mask gw $gw" >> $tempfile echo " down route -A inet6 del $net/$mask gw $gw" >> $tempfile else - echo " up route add -net $net netmask $mask gw $gw" >> $tempfile - echo " down route del -net $net netmask $mask gw $gw" >> $tempfile + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + echo " up route add -net $net netmask $mask dev $ifname" >> $tempfile + echo " down route del -net $net netmask $mask dev $ifname" >> $tempfile + else + echo " up route add -net $net netmask $mask gw $gw" >> $tempfile + echo " down route del -net $net netmask $mask gw $gw" >> $tempfile + fi fi fi mv -f $tempfile $filename @@ -279,8 +289,13 @@ add_persistent_route() route1="$ifname $net\/$mask $gw"; else filename="/etc/sysconfig/static-routes"; - route="any net $net netmask $mask gw $gw $ifname"; - route1="any net $net netmask $mask gw $gw $ifname"; + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + route="any net $net netmask $mask dev $ifname"; + route1="any net $net netmask $mask dev $ifname"; + else + route="any net $net netmask $mask gw $gw $ifname"; + route1="any net $net netmask $mask gw $gw $ifname"; + fi fi if [ -f $filename ]; then grep "$route" $filename 2>&1 1>/dev/null @@ -401,8 +416,13 @@ rm_persistent_route() route1="$ifname $net/$mask $gw" else filename="/etc/sysconfig/static-routes"; - route="any net $net netmask $mask gw $gw $ifname"; - route1="any net $net netmask $mask gw $gw $ifname"; + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + route="any net $net netmask $mask dev $ifname"; + route1="any net $net netmask $mask dev $ifname"; + else + route="any net $net netmask $mask gw $gw $ifname"; + route1="any net $net netmask $mask gw $gw $ifname"; + fi fi if [ -f $filename ]; then grep "$route" $filename 2>&1 1>/dev/null @@ -438,7 +458,11 @@ if [ "$op" = "add" ]; then fi else if [ "$(uname -s)" = "Linux" ]; then - cmd="route add -net $net netmask $mask gw $gw" + if [ "$gw" = "" -o "$gw" = "0.0.0.0" ] ; then + cmd="route add -net $net netmask $mask dev $ifname" + else + cmd="route add -net $net netmask $mask gw $gw" + fi else cmd="route add -net $net -netmask $mask $gw" fi