X-Git-Url: http://lab.mitty.jp/git/?a=blobdiff_plain;f=iproute%2Fsetroute-rhel.sh;h=9314dd96a17f811550e324da2ca934ce95f60e4a;hb=b9ae53a95b312d5a987461ac4966bcbb88e3c5b0;hp=e88bdc64d4218b131c8af175a1e7eb529d604317;hpb=c1094188ede7a1445e590417ab77e4020724332c;p=lab.git diff --git a/iproute/setroute-rhel.sh b/iproute/setroute-rhel.sh index e88bdc6..9314dd9 100755 --- a/iproute/setroute-rhel.sh +++ b/iproute/setroute-rhel.sh @@ -2,10 +2,10 @@ set -x -IF="${1:?"usage: $0 [gateway] "}" +IFACE="${1:?"usage: $0 [gateway] "}" GATEWAY=$2 -TID=`/sbin/ip addr show dev ${IF} | grep -w ${IF}: | cut -d : -f 1` +TID=`/sbin/ip addr show dev ${IFACE} | grep -w ${IFACE}: | tr -s ' ' | cut -d : -f 1` if [ "${GATEWAY}" = "down" ]; then # delete routing table and policy and exit @@ -14,30 +14,30 @@ if [ "${GATEWAY}" = "down" ]; then ## device has no longer any IP addr, so do not use IPADDR /sbin/ip rule del table ${TID} priority ${TID} /sbin/ip route flush cache - echo "remove routing table and policy for ${IF}" + echo "remove routing table and policy for ${IFACE}" exit fi # get IP address, network mask, default gateway info -IPADDR=`/sbin/ip addr show dev ${IF} | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1` -NETWORK=`/sbin/ip route show dev ${IF} | grep -w ${IPADDR} | cut -d ' ' -f 1` +IPADDR=`/sbin/ip addr show dev ${IFACE} | grep -w inet | tr -s ' ' | cut -d ' ' -f 3 | cut -d / -f 1` +NETWORK=`/sbin/ip route show dev ${IFACE} | grep -w ${IPADDR} | tr -s ' ' | cut -d ' ' -f 1` if [ -z "${GATEWAY}" ]; then - GATEWAY=`/sbin/ip route show dev ${IF} | grep -w default | cut -d ' ' -f 3` + GATEWAY=`/sbin/ip route show dev ${IFACE} | grep -w default | tr -s ' ' | cut -d ' ' -f 3` fi if [ -z "${GATEWAY}" ]; then - GATEWAY=`/sbin/ip route | grep -w default | cut -d ' ' -f 3` + GATEWAY=`/sbin/ip route | grep -w default | tr -s ' ' | cut -d ' ' -f 3` # this may add wrong default route especially on RHEL fi # set routing table -/sbin/ip route add ${NETWORK} dev ${IF} table ${TID} -/sbin/ip route add default via ${GATEWAY} dev ${IF} table ${TID} +/sbin/ip route add ${NETWORK} dev ${IFACE} table ${TID} +/sbin/ip route add default via ${GATEWAY} dev ${IFACE} table ${TID} # set routing policy /sbin/ip rule add from ${IPADDR} table ${TID} priority ${TID} /sbin/ip route flush cache -echo "add routing table and policy for ${IF} on table ${TID}" +echo "add routing table and policy for ${IFACE} on table ${TID}"