nat on Mac OSX Yosemite (the last OS version from Apple (that was the latest OS from Apple when this post was written) is not that simple to configure since natd binary (used for network address translation rules) or ipfw (used to create firewall rules on Mac OSX) are missing completely from the operating system. There were replaces with another tool. The new tool is pfctl (which has built-in network address translation support).

First of all you have to enable packet forwarding on your Mac computer. This can be done with 2 simple commands:

Now for the (Network Address Translation) part, the basic syntax is as follows:

nat on $ext_if from $localnet to any -> ($ext_if)
$ext_if = external interface (or the interface you use to connect to internet; could be an ethernet interface or wireless or even your wan interface, if your mac is directly connected to the internet.

Assuming your network interface is en0 (ethernet or wireless), in order to do NAT you have to create a pfctl rule. Let’s create a file called nat-rules

# cat > nat-rules
nat on en0 from $localnet to any -> (en0)

Save the file and now start pfctl using the rule from the file we have created earlier:

First rule disables pfctl. The second one, flushes all pfctl rules. The third one starts pfctl and loads the rules from nat-rules file. That’s it!


About Author

I am a linux passionate and currently working as a Linux Senior System Administrator. I also am a freelancer and help people to complete different jobs. You can hire me on