#!/bin/sh # # /etc/init.d/policyroute # Markus Förster (http://www.1ster.de/) # ### BEGIN INIT INFO # Provides: policyroute # Required-Start: $network # Required-Stop: # Default-Start: 3 5 # Default-Stop: # Description: Set up policy based routing ### END INIT INFO . /etc/rc.status # First reset status of this service rc_reset # Secondary Gateway and secondary IP address GATEWAY2="10.1.1.2" MYIP2="10.1.1.102" case "$1" in start) echo -n "Starting policy-based routing" ip route list | grep -v default | while read a; do ip route add table 1 $a; done ip route add table 1 default via $GATEWAY2 dev eth1 ip rule add from $MYIP2 table 1 priority 10000 rc_status -v echo ;; stop) ip rule delete from $MYIP2 table 1 priority 10000 ip route flush table 1 rc_status -v echo ;; restart|reload|force-reload) $0 stop $0 start rc_status ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 ;; esac rc_exit