Created
October 5, 2011 14:12
-
-
Save tonyskapunk/1264519 to your computer and use it in GitHub Desktop.
fix vpn route
This file contains 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
[cronjob] | |
*/5 * * * * /some/path/vpn/fix_route.sh | |
=== | |
[fix_route.sh] | |
#!/bin/bash | |
# Sets the correct route to send all traffic through VPN | |
iface_gw=$(/sbin/route -n|grep -P "^(0\.){3}0\s+(\d+\.){3}\d+\s+(0\.){3}0\s+"|awk '{print $NF}') | |
default_gw=$(/sbin/route -n|grep -P "^(0\.){3}0\s+(\d+\.){3}\d+\s+(0\.){3}0\s+"|awk '{print $2}') | |
correct_iface="tun0" | |
current_ip=$(/some/path/vpn/vpn_ip.sh) | |
if [ $? -ne 0 ] # Not using VPN Tunnel | |
then | |
exit 0 | |
fi | |
if [ $iface_gw != $correct_iface ] | |
then | |
sudo route del -net 0.0.0.0 gw $default_gw | |
sudo route add -net 0.0.0.0/0 dev tun0 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment