Even if Mac-OSX has a Unix core, Apple put some layers on top of it, which makes it rather hard to freely hack around. That's why I wrote an own small DHCP server recently. Configuring a Mac (Macbook Pro in my case) to act as a NAT router is hairy as well. Sure, there are the sharing options, but they're quite limited and bring their own DHCP server, with no control over it anymore.
On your Mac, choose Apple menu System Preferences, then click Sharing. Set up Internet Sharing on Mac OSX using Command Line Tools July 3rd, 2017. Even if Mac-OSX has a Unix core, Apple put some layers on top of it, which makes it rather hard to freely hack around. That's why I wrote an own small DHCP server recently. Configuring a Mac (Macbook Pro in my case) to act as a NAT router is hairy as well.
Setting up NAT by appealing to the core of OSX is not that hard. I assume your Mac (=router) has a Wifi connection to the internet (en0, configured with upstream DHCP). A network interface (en4), connected to the network which needs to be connected to the internet has a static IP address 192.168.3.1. You can set this static IP address either via the network settings or via the Terminal:
Note: ifconfig would work as well, but can be overwritten by the network settings. So using networksetup is the better option.
Enable IP forwarding on OSX
Now we need to enable packet forwarding. This can be accomplished with the following command:
You can connect your Mac computer to a TV with a cable or wirelessly if you have the right equipment. Here's what you need to connect your Mac and TV.
Sharing a Windows Computer's Connection: Configure your devices on the network.
Now the interesting part. Apple changed the way NAT works quite often over the last versions of OSX. The most recent way is to use pfctl. To do this, add the following line to /etc/pf.conf:
Remember: en0 is the Wifi network with internet connection, en4 is the local network connection. To activate the change run the following commands:
What Channel For Internet Sharing Machine
Configure the clients
Either you use an own DHCP server or configure the other devices statically. In my case, it's just a Raspberry PI, which needs to be connected to the internet, so setting it statically can be done with:
To make this change permanent, edit /etc/network/interfaces and set the following attributes:
To make the change work, run
You might also be interested in the following
Sorry, comments are closed for this article. Contact me if you want to leave a note.