In order to share your OpenVPN connection on OS X Mavericks, Yosemite or El Capitan enter the following commands to enable packet forwarding:
sudo sysctl -w net.inet.ip.forwarding=1
sudo sysctl -w net.inet.ip.fw.enable=1
Next add the following lines to
/etc/pf.conf immediately after
nat on $ext_if from $lan to any -> ($ext_if)
nat on $vpn_if from $lan to any -> ($vpn_if)
Note that you should change the lan address to the lan you want to route over the OpenVPN connection.
ext_if should be the interface that is connected to the lan.
vpn_if should be the OpenVPN interface. I used VyprVPN which used
tun0 rather than
utun0 so you may need to change this depending on your particular configuration.
Next run the following to load the config:
sudo pfctl -d
sudo pfctl -F all
sudo pfctl -f /etc/pf.conf -e
The instructions to do this were found here: http://www.douglas.wiki.br/doku.php?id=en:configuring_nat_on_mac_osx_yosemite
Loading with a daemon
If you want this to load automatically you can take a look at this repo https://github.com/essandess/osx-openvpn-server where you'll see an example of using a shell script with a .plist file to create a daemon that's loaded on boot. I just added
/sbin/pfctl -f /etc/pf.conf -e to the end of
enable-vpn-forward-nat.sh and did the following:
sudo mkdir '/Library/Application Support/vpn'
sudo install -m 755 osx-openvpn-server/enable-vpn-forward-nat.sh '/Library/Application Support/vpn'
sudo install -m 644 net.openvpn.enable-vpn-forward-nat.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/net.openvpn.enable-vpn-forward-nat.plist