Changing the IP address for OS X’s shared network
When I’m developing software on small and embedded devices I tend to network them by using a CAT-6 cable between a network port on my Mac and the device and enable Internet Sharing via System Preferences. Unfortunately OS X always selects 192.168.2.0 as the network address and this may class with other networks on your network. Recently I found out how to change this.
I have an Apple USB Network Adapter that I use to provide a second network port. I connect this, using a CAT-6 cable, directly to my target device when developing. Enabling Internet Sharing will forward network traffic from either my primary ethernet port or wi-fi adapter. The only problem with this is the network IP address as I said above. This seems to be a hardcoded default.
However behind all the UI utilities Apple has command line ones that do the grunt work. Internet Sharing is no different. Checking out the man page for InternetSharing provides all sorts of gems.
$ man InternetSharing
Specifically these two snippets of information. This:
InternetSharing reads the property list com.apple.nat.plist stored in the /Library/Preferences/SystemConfiguration.
One property worth mentioning is SharingNetworkNumberStart. This prop- erty controls the behavior of InternetSharing when it configures IP addresses for the local interfaces. The property is encoded as a string containing the dotted decimal network IP address, assumed to be a class C network.
You can change the network IP address for the private network by defining a new value for the SharingNetworkNumberStart property.
Open a terminal and edit the file /Library/Preferences/SystemConfiguration/com.apple.nat.plist in vim. (You will need to us sudo to give you administrator/super-user privileges.)
$ sudo vim /Library/Preferences/SystemConfiguration/com.apple.nat.plist
At the bottom of the file, just above the second from bottom </dict> add a key value pair for SharingNetworkNumberStart as follows:
<key>SharingNetworkNumberStart</key> <string>192.168.111.0</string> </dict> </dict> </plist>
Where the 192.168.111.0 can be any network IP address you choose.
Once edited if you restart Internet Sharing you will see the new IP address is used for the network.
Tags: Internet sharing