Share OSX VPN with your Pi

I have a raspberry Pi that I wanted to connect to my office network for running a test. Rather than setting up a complete VPN connection on the Pi for just a one-off test, much better if the Pi shares the VPN connection from my MacBook.

Getting your MacBook to share its VPN connection is actually not difficult. First enable forwarding:

$ sudo sysctl -w net.inet.ip.forwarding=1

Next create a file called nat-rules with the following content:

nat on ppp0 from en0:network to any -> (ppp0)