Skip to content

Instantly share code, notes, and snippets.

@alotaiba
Created June 18, 2011 18:01
Show Gist options
  • Save alotaiba/1033342 to your computer and use it in GitHub Desktop.
Save alotaiba/1033342 to your computer and use it in GitHub Desktop.
This script is to turn on/off NATting through to a VPN server on Mac.
#!/bin/bash
# This script to turn on/off NATting through to a VPN server.
# Example would be turning the mac into a wireless router, and routing all the incoming
# traffic to the VPN server.
# Thanks to http://rodrigo.sharpcube.com/2010/06/20/using-and-sharing-a-vpn-connection-on-your-mac/
case "$1" in
on)
echo "Turning NAT VPN on."
natd -interface tun0
ipfw -f flush
ipfw add divert natd ip from any to any via tun0
ipfw add pass all from any to any
sysctl -w net.inet.ip.forwarding=1
;;
off)
echo "Turning NAT VPN off."
killall natd
ipfw -f flush
sysctl -w net.inet.ip.forwarding=0
;;
*)
echo "To use the script, you can either turn the NAT VPN on or off:"
echo "./natvpn.sh on"
echo "./natvpn.sh off"
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment