Last active
December 19, 2015 08:29
-
-
Save zhouqt/5926455 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
ping_test() | |
{ | |
out_iface=$1 | |
target=$2 | |
ping -q -I $out_iface -c $detect_pkt_num -w $detect_timeout $target > /dev/null | |
return $? | |
} | |
route_prefix="114.114.114.0/24" | |
default_rt=`ip route show exact $route_prefix` | |
detect_target="114.114.114.114" | |
detect_pkt_num=3 | |
detect_timeout=10 | |
ip route add 114.114.114.114/32 via 192.168.200.1 dev tap2 | |
ping_test "tap2" "114.114.114.114" | |
if [ $? -eq 1 ]; then | |
echo $default_rt | grep "192.168.200.1" | |
if [ $? -eq 0 ]; then | |
ip route replace 114.114.114.0/24 via 192.168.4.1 | |
fi | |
else | |
echo $default_rt | grep "192.168.200.1" | |
if [ $? -eq 1 ]; then | |
ip route replace $route_prefix nexthop ${default_rt#* } nexthop via 192.168.200.1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment