Created
March 3, 2017 12:15
-
-
Save xnoder/dfe4378443318006f2bb2677f7e4d017 to your computer and use it in GitHub Desktop.
A ZSH script to rebuild my macos routing table for whichever network I am on so that I can run my FortiClient VPN permanently without having all traffic tunnelled up the utun1 interface by the VPN config
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
#!/bin/zsh | |
usage() { | |
print "Usage: sudo rerouter -n network" | |
exit 1 | |
} | |
while getopts ':n:' arg; do | |
case $arg in | |
n) | |
NET=$OPTARG | |
;; | |
\?) | |
print "Invalid option -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
print "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
if [ "$NET" = "office" ]; then | |
DEFAULTGW="10.1.42.65" | |
elif [ "$NET" = "home" ]; then | |
DEFAULTGW="192.168.0.1" | |
elif [ "$NET" = "hotspot" ]; then | |
DEFAULTGW="0.0.0.0" | |
else | |
print "Sorry. Unrecognised network." | |
exit 1 | |
fi | |
print "Rebuilding routing table for $NET." | |
sudo route delete default | |
sudo route add default $DEFAULTGW | |
sudo route -n add -net 192.168.0.0/24 172.27.1.100 | |
sudo route -n add -net 192.168.101.0/24 172.27.1.100 | |
sudo route -n add -net 192.168.102.0/24 172.27.1.100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment