Apple - How can I setup my mac (OS X Yosemite) as an internet gateway
OS X Yosemite doesn’t have support for natd binary or ipfw anymore. Instead pfctl is used.
I assume the following IP-adresses/netmasks:
Router: 192.168.0.1/24
Mac mini gateway: en0: 192.168.0.2/24 gateway 192.168.0.1 en1: 192.168.1.2/24
Internal network: 192.168.1.0/24
First you have to enable forwarding on your Mac computer with following commands:
sudo sysctl -w net.inet.ip.forwarding=1
In order to do NAT you have to create a pfctl rule. Create a file called "nat-rules" with the following content:
nat on en0 from en1 to any -> (en0)
Save the file and now start pfctl using the rule from the file we have created earlier:
sudo pfctl -d #disables pfctl sudo pfctl -F all #flushes all pfctl rules sudo pfctl -f /Path/to/file/nat-rules -e #starts pfctl and loads the rules from the nat-rules file
Now configure a static route on your router:
192.168.1.0/24 (the internal network) -> 192.168.0.2 (Mac mini IP-address of the external interface connected to the router)
Enable the DHCP-service on your Mac mini gateway:
- Name: choose a name
- Network Interface: en1
- Starting IP address: 192.168.1.10
- Ending IP address: 192.168.1.100
- Subnet Netmask: 255.255.255.0
- Router: 192.168.1.2
- DNS: some DNS-server (e.g. 8.8.8.8)
Now use pfctl to add rules or get a pfctl-GUI like IceFloor or Murus to configure your firewall. Both apps should also allow you to enable NAT (step 2/3)
Have you tried System Preferences > Sharing and enabling Internet Sharing (select the USB connection to the router as the Internet interface you're sharing)?