#!/bin/sh # copyright 2003 Alexey Toptygin # debianized by alexeytATfreeshell.org Sep 2004 # # customized for CHANGEME # list of all custom tables you use (remember to update rt_tables) TABLES='' if [ ! -x /sbin/ip ]; then { echo "iproute: could not find /sbin/ip !!!"; exit 1; } fi # check that the needed tables are known by iproute for i in $TABLES; do { if [ " $i" != " main" ]; then { foo=`grep -v "^\w*#" /etc/iproute2/rt_tables | grep -c $i` if [ $foo != 1 ]; then { echo "iproute: could not find table $i, quitting" exit 1 } fi } fi } done if [ `id -u` -ne 0 ]; then { echo "iproute: must be superuser" exit 1 } fi start() { echo -n "Removing user defined rules: " rules=`ip rule ls | egrep -v "^(0|32766|32767):" | cut -d ':' -f 1` error= for i in $rules; do { ip rule del prio $i || error=1 } done [ $error ] && echo "FAILED." || echo "done." echo -n "Flushing user defined route tables: " error= for i in $TABLES; do { ip route flush table $i || error=1 } done [ $error ] && echo "FAILED." || echo "done." echo -n "Adding rules and routes: " # add rules and routes here like so: ip route add default via 10.0.0.1 dev eth0 && \ echo "done." || echo "FAILED." echo -n "Flushing route cache: " ip route flush cache && \ echo "done." || echo "FAILED." } stop() { rules=`ip rule ls | egrep -v "^(0|32766|32767):" | cut -d ':' -f 1` echo -n "Removing user defined rules: " error= for i in $rules; do { ip rule del prio $i || error=1 } done [ $error ] && echo "FAILED." || echo "done." echo -n "Flushing user defined route tables: " error= for i in $TABLES; do { ip route flush table $i || error=1 } done [ $error ] && echo "FAILED." || echo "done." echo -n "Flushing route cache: " ip route flush cache && \ echo "done." || echo "FAILED." } status() { echo " Rules:" ip rule ls echo echo " Table main:" ip route ls echo for i in $TABLES; do { echo " Table $i:" ip route ls table $i echo } done } case "$1" in start) start;; stop) stop;; restart) start;; status) status;; *) echo "Usage: $0 {start|stop|restart|status}";; esac exit 0