Skip to content

Instantly share code, notes, and snippets.

@tonyskapunk
Created October 5, 2011 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyskapunk/1264519 to your computer and use it in GitHub Desktop.
Save tonyskapunk/1264519 to your computer and use it in GitHub Desktop.
fix vpn route
[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