If the commands for configuring OS X 10.8.2 as router with NAT are executed at startup with a DaemonLaunch Process , there has to be a "sleep 15" in the script, cause the network interface needs time to be up, otherwise the network interface wont work at all.
Complete solution for routing and NAT after restart of OS X 10.8.2 server:
1) Create directory and script for executing the command:
Code: Select all
su
mkdir /Library/Application\ Support/vpn
vi /Library/Application\ Support/vpn/enable-vpn-forward-nat.sh
Content for "enable-vpn-forward-nat.sh":
Code: Select all
#!/bin/bash
#
# Sleep is necessary cause network has to be up at the time of following commands
# Otherwise the network will not work at all
#
sleep 15
#
sysctl -w net.inet.ip.fw.enable=1
sysctl -w net.inet.ip.forwarding=1
natd -interface en0
ipfw add divert natd ip from any to any via en0
Set file "enable-vpn-forward-nat.sh" executable:
Code: Select all
chmod 755 /Library/Application\ Support/vpn/enable-vpn-forward-nat.sh
Create LaunchDaemon "enable-vpn-forward-nat.plist":
Code: Select all
su
vi /Library/LaunchDaemons/enable-vpn-forward-nat.plist
Content for "enable-vpn-forward-nat.plist":
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>enable-vpn-forward-nat</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Application Support/vpn/enable-vpn-forward-nat.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Imporant: A path with spaces (as ".../Application Support/...") does not get the "\" as escape character in the .plist file.
Test load of Daemon (check errors in console):
Code: Select all
launchctl load enable-vpn-forward-nat.plist
Now routing and NAT are also available after a restart (= permanently)