source: lab.git/iproute/setroute-rhel.sh @ 4a36a1b

trunk
Last change on this file since 4a36a1b was 8c804d8, checked in by mitty <mitty@…>, 15 years ago
  • setroute.sh
    • rewrite codes with environment variables given by INTERFACES(5)
  • setroute-rhel.sh
    • RHEL capable version

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@6 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

  • Property mode set to 100644
File size: 1.3 KB
Line 
1#!/bin/sh
2
3set -x
4
5IF="${1:?"usage: $0 <ether_device> [gateway] "}"
6GATEWAY=$2
7
8TID=`/sbin/ip addr show dev ${IF} | grep -w ${IF}: | cut -d : -f 1`
9
10if [ "${GATEWAY}" = "down" ]; then
11    # delete routing table and policy and exit
12    ## routing table is automatically flushed, so 'route flush' can be removed
13    /sbin/ip route flush table ${TID}
14    ## device has no longer any IP addr, so do not use IPADDR
15    /sbin/ip rule del table ${TID} priority ${TID}
16    /sbin/ip route flush cache
17    echo "remove routing table and policy for ${IF}"
18    exit
19fi
20
21
22# get IP address, network mask, default gateway info
23IPADDR=`/sbin/ip addr show dev ${IF} | grep -w inet | cut -d t -f 2 | cut -d ' ' -f 2 | cut -d / -f 1`
24NETWORK=`/sbin/ip route show dev ${IF} | grep -w ${IPADDR} | cut -d ' ' -f 1`
25
26if [ -z "${GATEWAY}" ]; then
27    GATEWAY=`/sbin/ip route show dev ${IF} | grep -w default | cut -d ' ' -f 3`
28fi
29if [ -z "${GATEWAY}" ]; then
30    GATEWAY=`/sbin/ip route | grep -w default | cut -d ' ' -f 3`
31    # this may add wrong default route especially on RHEL
32fi
33
34
35# 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}
38
39# set routing policy
40/sbin/ip rule add from ${IPADDR} table ${TID} priority ${TID}
41
42/sbin/ip route flush cache
43echo "add routing table and policy for ${IF} on table ${TID}"
Note: See TracBrowser for help on using the repository browser.