Skip to content

Instantly share code, notes, and snippets.

@ajbogh
Created December 24, 2014 07:30
Show Gist options
  • Save ajbogh/9a15138abcde619950a1 to your computer and use it in GitHub Desktop.
Save ajbogh/9a15138abcde619950a1 to your computer and use it in GitHub Desktop.
FixVPN routes all traffic through a local interface, except for VPN's IPs, allowing internet access.
#!/bin/bash
# Notes: use the route command to determine your device name and make changes below.
# Run this script only after you connect to the VPN.
##### EDIT BELOW #####
NETWORK_DEVICE='wlan0'
##### END EDITABLE SECTION #####
if ! hash gksu 2>/dev/null; then
#install gksu
zenity --warning --title="Missing dependency" --text="Please install gksu by typing 'sudo apt-get install gksu' from a terminal or search for gksu in the Ubuntu Software Center."
exit 0
fi
# Elevate privileges to run the route commands
[ "$UID" -eq 0 ] || exec gksu bash "$0" "$@"
PERSONAL_GATEWAY=`ip route | grep "via" -m 1 | cut -d" " -f 3`
# Remove default route because it doesn't allow internet access
route del default vpn0
# Add a new default route that does allow internet access
route add default gw $PERSONAL_GATEWAY $NETWORK_DEVICE
# NOTE: Any search or browser request will use the default route
# This ensures searches won't hit the VPN and other websites
# won't be blocked by the corporate security policy.
# Please use caution when browsing the internet or downloading files.
# route all traffic in the 10.x.x.x IP block to the VPN.
route add -net 10.0.0.0 netmask 255.0.0.0 dev vpn0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment