Changeset 8c804d8 in lab.git for iproute/setroute.sh
- Timestamp:
- Jun 29, 2009 5:56:34 PM (15 years ago)
- Branches:
- master, trunk
- Children:
- 84c2881
- Parents:
- be2a37e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
iproute/setroute.sh
rbe2a37e r8c804d8 3 3 set -x 4 4 5 IF="${1:?"usage: $0 <ether_device> [gateway] "}" 6 GATEWAY=$2 5 ## INTERFACES(5) 6 # IFACE physical name of the interface being processed 7 # METHOD method of the interface (e.g., static) 8 # MODE start if run from ifup, stop if run from ifdown 9 # PHASE as per MODE, but with finer granularity, distinguishing the pre- 10 # up, post-up, pre-down and post-down phases. 7 11 8 TID=`/sbin/ip addr show dev ${IF} | grep -w ${IF}: | cut -d : -f 1` 12 # optional arugument to set default gateway manually 13 GATEWAY=$1 9 14 10 if [ "${GATEWAY}" = "down" ]; then 15 TID=`/sbin/ip addr show dev ${IFACE} | grep -w ${IFACE}: | cut -d : -f 1` 16 17 if [ "${PHASE}" = "post-down" ]; then 11 18 # delete routing table and policy and exit 12 19 ## routing table is automatically flushed, so 'route flush' can be removed … … 15 22 /sbin/ip rule del table ${TID} priority ${TID} 16 23 /sbin/ip route flush cache 17 echo "remove routing table and policy for ${IF }"24 echo "remove routing table and policy for ${IFACE}" 18 25 exit 19 26 fi … … 21 28 22 29 # get IP address, network mask, default gateway info 23 IPADDR=`/sbin/ip addr show dev ${IF } | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1`24 NETWORK=`/sbin/ip route show dev ${IF } | grep -w ${IPADDR} | cut -d ' ' -f 1`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 NETWORK=`/sbin/ip route show dev ${IFACE} | grep -w ${IPADDR} | cut -d ' ' -f 1` 25 32 26 33 if [ -z "${GATEWAY}" ]; then 27 GATEWAY=`/sbin/ip route show dev ${IF } | grep -w default | cut -d ' ' -f 3`34 GATEWAY=`/sbin/ip route show dev ${IFACE} | grep -w default | cut -d ' ' -f 3` 28 35 fi 29 36 if [ -z "${GATEWAY}" ]; then … … 34 41 35 42 # set routing table 36 /sbin/ip route add ${NETWORK} dev ${IF } table ${TID}37 /sbin/ip route add default via ${GATEWAY} dev ${IF } table ${TID}43 /sbin/ip route add ${NETWORK} dev ${IFACE} table ${TID} 44 /sbin/ip route add default via ${GATEWAY} dev ${IFACE} table ${TID} 38 45 39 46 # set routing policy … … 41 48 42 49 /sbin/ip route flush cache 43 echo "add routing table and policy for ${IF } on table ${TID}"50 echo "add routing table and policy for ${IFACE} on table ${TID}"
Note: See TracChangeset
for help on using the changeset viewer.