6 # IFACE physical name of the interface being processed
7 # METHOD method of the interface (e.g., static)
\r
8 # MODE start if run from ifup, stop if run from ifdown
\r
9 # PHASE as per MODE, but with finer granularity, distinguishing the pre-
\r
10 # up, post-up, pre-down and post-down phases.
\r
12 # optional arugument to set default gateway manually
15 TID=`/sbin/ip addr show dev ${IFACE} | grep -w ${IFACE}: | cut -d : -f 1`
17 if [ "${PHASE}" = "post-down" ]; then
18 # delete routing table and policy and exit
19 ## routing table is automatically flushed, so 'route flush' can be removed
20 /sbin/ip route flush table ${TID}
21 ## device has no longer any IP addr, so do not use IPADDR
22 /sbin/ip rule del table ${TID} priority ${TID}
23 /sbin/ip route flush cache
24 echo "remove routing table and policy for ${IFACE}"
29 # get IP address, network mask, default gateway info
30 IPADDR=`/sbin/ip addr show dev ${IFACE} | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1`
31 if [ -z ${IPADDR} ]; then
32 # fail to bind IP address to device
33 echo "${IFACE} has no IP address."
36 NETWORK=`/sbin/ip route show dev ${IFACE} | grep -w ${IPADDR} | cut -d ' ' -f 1`
38 if [ -z "${GATEWAY}" ]; then
39 GATEWAY=`/sbin/ip route show dev ${IFACE} | grep -w default | cut -d ' ' -f 3`
41 if [ -z "${GATEWAY}" ]; then
42 GATEWAY=`/sbin/ip route | grep -w default | cut -d ' ' -f 3`
43 # this may add wrong default route especially on RHEL
48 /sbin/ip route add ${NETWORK} dev ${IFACE} table ${TID}
49 /sbin/ip route add default via ${GATEWAY} dev ${IFACE} table ${TID}
52 /sbin/ip rule add from ${IPADDR} table ${TID} priority ${TID}
54 /sbin/ip route flush cache
55 echo "add routing table and policy for ${IFACE} on table ${TID}"