#!/bin/bash # #!F:delip4routes # #!P:/usr/local/sbin # #!D:Deletes all IPv4 routes through a specified interface # #!C:Copyright 1997-1998 Peter Bieringer # #!V:Version 1.04 18.07.1998 # Changes to # 1.01: info display # 1.02: net-tools-980126 correction (route won't display U) # 1.03: minor revision # 1.04: remove net-tools-980126 correction (now obsolete) # Here a shortcut to "route" ROUTE="/sbin/route -n -A inet" ## Subroutines # Display information info() { grep "^#!D" $0 | awk -F: '{ print $2}' grep "^#!C" $0 | awk -F: '{ print " " $2}' grep "^#!V" $0 | awk -F: '{ print " " $2}' echo } # Help subroutine help() { echo echo " Usage: $0 interface" return } ## Start info DEVNAME=$1 if [ "$DEVNAME" = "" ]; then echo " No interface name is given - stop!" help exit 1 fi; echo " You specified interface '$DEVNAME'" # Get routes and delete the ones which matches $DEVNAME $ROUTE | grep $DEVNAME | while read dest gw mask flags metric ref use iface; do # Compare interface name if [ "$iface" = "$DEVNAME" ]; then # Test if route is up? if echo $flags | grep U >/dev/null 2>&1; then # route through gateway ? if [ "$gw" = "*" ]; then echo " del $dest netmask $mask dev $iface" $ROUTE del -net $dest netmask $mask dev $iface else echo " del $dest gw $gw netmask $mask dev $iface" $ROUTE del -net $dest gw $gw netmask $mask dev $iface fi fi fi done echo " Done!"