Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # installation: copy/paste this script into shell (telnet/ssh) window
- WANUP_DIR="/jffs/etc/config"
- WANUP_SCRIPT="$WANUP_DIR/alt-gtwy.wanup"
- mkdir -p $WANUP_DIR
- cat << "EOF" > $WANUP_SCRIPT
- #!/bin/sh
- set -x # uncomment/comment to enable/disable debug mode
- (
- TID='200'
- ALT_GTWY='192.168.1.88'
- # source IPs to be routed via 192.168.1.1
- SOURCE_IP='
- 192.168.3.177
- 192.168.3.178
- 192.168.3.179
- 192.168.3.180
- 192.168.3.181
- 192.168.3.182
- 192.168.3.183
- 192.168.3.184
- 192.168.3.185
- 192.168.3.186
- 192.168.3.187
- '
- # required for serialization when reentry is possible
- LOCK="/tmp/$(basename $0).lock"
- acquire_lock() { while ! mkdir $LOCK >/dev/null 2>&1; do sleep 10; done; }
- release_lock() { rmdir $LOCK >/dev/null 2>&1; }
- # optional (allows recovery period of two minutes)
- #sleep 120
- # wait for *reliable* internet connection
- while ! ping -qc1 -w3 8.8.8.8 >/dev/null 2>&1; do sleep 3; done; sleep 10
- # one instance at a time
- acquire_lock
- # catch premature exit and cleanup
- trap 'release_lock; exit 1' SIGHUP SIGINT SIGTERM
- # cleanup from possible prior execution
- {
- ip route del 0.0.0.0/1 via $ALT_GTWY
- ip route del 128.0.0.0/1 via $ALT_GTWY
- while ip rule del from 0/0 to 0/0 table $TID 2>/dev/null; do :; done
- ip route flush table $TID
- ip route flush cache
- } 2>/dev/null
- # copy main routing table to alternate
- ip route | while read route; do ip route add $route table $TID; done
- # override main routing table w/ alternate gateway
- ip route add 0.0.0.0/1 via $ALT_GTWY
- ip route add 128.0.0.0/1 via $ALT_GTWY
- # start split gateway
- for ip in $SOURCE_IP; do ip rule add from $ip table $TID; done
- # force routing system to recognize changes
- ip route flush cache
- # any concurrent instance(s) may now run
- release_lock
- exit 0
- ) 2>&1 | logger -t $(basename $0)[$$] &
- EOF
- chmod +x $WANUP_SCRIPT
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement