Little script to save and restore ip rules

Linux Advanced Routing and Traffic Control

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

I would like to have some testers for this script which should save and restore ip rules and associated tables.

Thanks

#!/bin/bash
#
# chkconfig: 2345 85 15
# description: save and restore ip rules settings
# config: /etc/sysconfig/iprules

# source function library
. /etc/rc.d/init.d/functions

CONFIG=/etc/sysconfig/iprules

RETVAL=0

case "$1" in
save)
echo -n "Saving ip rules:"
rm $CONFIG > /dev/null 2>&1
ip ru ls | grep -v "^3276.:" | grep -v "^0:" | sed -e "s/://" -e "s/from all//" -e "s/^/ip ru add preference /" |
echo $LINE >> $CONFIG
done
ip ru ls | grep -v "lookup local" | grep -v "lookup main" | grep -v "lookup default" | sed -e "s/^.*lookup //" |
ip ro ls ta $LINE | sed -e "s/$/ ta $LINE/" -e "s/^/ip ro add /" >> $CONFIG
done
echo
;;
stop)
echo -n "Stopping ip rules:"
ip ru ls | grep -v "lookup local" | grep -v "lookup main" | grep -v "lookup default" | sed -e "s/^.*lookup //" |
ip ro flush ta $LINE
done
ip ru ls | grep -v "^3276.:" | grep -v "^0:" | sed -e "s/://" -e "s/from all//" -e "s/^/ip ru del preference /"
/sbin/$LINE
done
rm -f /var/lock/subsys/rules
echo
;;
start)
echo -n "Starting ip rules:"
if [ -f /var/lock/subsys/rules ] ; then
$0 stop
fi
# real start
cat $CONFIG | while read LINE ; do
/sbin/$LINE
done
touch /var/lock/subsys/rules
echo
;;
restart|reload)
$0 stop
$0 start
RETVAL=$?
;;
status)
status gpm
RETVAL=$?
;;
*)
echo "Usage: gpm {start|stop|status|restart|reload}"
exit 1
esac


exit $RETVAL

_______________________________________________
LARTC mailing list / LARTC@xxxxxxxxxxxxxxx
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/

[Index of Archives]     [LARTC Home Page]     [Netfilter]     [Netfilter Development]     [Network Development]     [Bugtraq]     [GCC Help]     [Yosemite News]     [Linux Kernel]     [Fedora Users]
  Powered by Linux