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.

And this:

     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:

4 Responses to “Changing the IP address for OS X’s shared network”

  1. alecthegeek Says:

    This does not seem to work in OS X.8 (Mountain Lion).

    Another handy hint is that you can save the editing with the command

    sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.nat SharingNetworkNumberStart 192.168.100.1

    However this still does not work on X.8 :-(

  2. alecthegeek Says:

    Mmmm — after a lot of futzing around my problems are due to VMWare networking messing things up. Iz all gud now. Please ignore my previous comments

  3. wasp digital Says:

    Actually this only works if you first close system preferences. Otherwise there is some caching that system preferences does, and the changes get overwritten.

  4. DaZ Says:

    That post helped me achieve this in Mountain Lion

    http://hints.macworld.com/article.php?story=20090510120814850

    I had to completly close System Preferences before editing, and Add the key/string pair to AirPort Subset.

Leave a Reply