Changeset 6 in lab


Ignore:
Timestamp:
Jun 29, 2009 5:56:34 PM (15 years ago)
Author:
mitty
Message:
  • setroute.sh
    • rewrite codes with environment variables given by INTERFACES(5)
  • setroute-rhel.sh
    • RHEL capable version
Location:
trunk/iproute
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/iproute/setroute.sh

    r5 r6  
    33set -x 
    44 
    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. 
    711 
    8 TID=`/sbin/ip addr show dev ${IF} | grep -w ${IF}: | cut -d : -f 1` 
     12# optional arugument to set default gateway manually 
     13GATEWAY=$1 
    914 
    10 if [ "${GATEWAY}" = "down" ]; then 
     15TID=`/sbin/ip addr show dev ${IFACE} | grep -w ${IFACE}: | cut -d : -f 1` 
     16 
     17if [ "${PHASE}" = "post-down" ]; then 
    1118    # delete routing table and policy and exit 
    1219    ## routing table is automatically flushed, so 'route flush' can be removed 
     
    1522    /sbin/ip rule del table ${TID} priority ${TID} 
    1623    /sbin/ip route flush cache 
    17     echo "remove routing table and policy for ${IF}" 
     24    echo "remove routing table and policy for ${IFACE}" 
    1825    exit 
    1926fi 
     
    2128 
    2229# 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` 
     30IPADDR=`/sbin/ip addr show dev ${IFACE} | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1` 
     31NETWORK=`/sbin/ip route show dev ${IFACE} | grep -w ${IPADDR} | cut -d ' ' -f 1` 
    2532 
    2633if [ -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` 
    2835fi 
    2936if [ -z "${GATEWAY}" ]; then 
     
    3441 
    3542# 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} 
    3845 
    3946# set routing policy 
     
    4148 
    4249/sbin/ip route flush cache 
    43 echo "add routing table and policy for ${IF} on table ${TID}" 
     50echo "add routing table and policy for ${IFACE} on table ${TID}" 
Note: See TracChangeset for help on using the changeset viewer.