Configuring the Network used by Mac OS X Internet Connection Sharing

by
Tags: , ,

Changing the Subnet

On Mac OS X, Internet Connection Sharing by default hands out IPs on the 192.168.2.x subnet.  Normally this is fine, but sometimes you might want to change it (because you’re at a hotel that uses 192.168.2.x or whatever).

The network to use is configured in /etc/bootpd.plist, but that file is overwritten every time you start Internet Connection Sharing (and deleted when you stop it).

Before you do anything else, you should start Internet Connection Sharing once (through the Sharing pane of the System Preferences app), in order to make sure all the configuration files are generated.

The easiest way to change the network is to shut down Internet Connection Sharing, close System Preferences entirely (since it keeps settings in memory and overwrites configuration files), and run the following Terminal command (replacing the last parameter with the network you want it to use):

sudo defaults write
   /Library/Preferences/SystemConfiguration/com.apple.nat
   NAT -dict-add SharingNetworkNumberStart 192.168.3.0

Then you can go back into System Preferences and start Internet Connection Sharing again.  If you look at /etc/bootpd.plist, you should see the new network listed.

Static IPs for Connected Devices

If you want to assign static IPs to any devices, you can create the file /etc/bootptab like this:

# Bootptab file
# Section 1 -- ignored
%%
# Section 2 -- used
# Hardware types: 1=Ethernet, 6=Wireless
#                 See http://www.ietf.org/rfc/rfc1700.txt
#
# machine entries have the following format:
#
# hostname         hwtype     hwaddr         ipaddr   bootfile
some-ethernet-machine 1 c4:2c:03:3a:7f:65 192.168.3.200 boot
a-wireless-machine    6 60:33:4b:27:6c:62 192.168.3.201 boot
another-ethernet      1 00:0d:93:72:e7:96 192.168.3.202 boot

You can man bootptab, though it isn’t very helpful, and man bootpd has only a little more.  Bottom line, there must be a line with %% and the static IP definitions come after that.  The first parameter is the machine name, the second is the hardware type, the third is the Ethernet address of the relevant network interface of the machine, the fourth is the IP to assign, and the last is a boot file (which we aren’t using, but it might be necessary to have something there).

Make sure to restart Internet Connection Sharing after editing this file.