Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Change the default subnet for Internet Sharing Internet
For some time, I googled and hunted for a solution that would allow me to change the subnet that Internet Sharing (on the Sharing System Preferences panel) uses when sharing onto an Ethernet network -- the default being 192.168.2.0. In my case, this also happens to be a subnet used by my corporate VPN, which is not too convenient.

The solution for Leopard turned out to be extremely straightforward, and can be found in the unix help file for InternetSharing -- just type man InternetSharing to read it in Terminal:
  1. Copy the plist file /Library » Preferences » SystemConfiguration » com.apple.nat.plist to your home directory, eg: sudo cp /Library/Preferences/SystemConfiguration/com.apple.nat.plist ~.
  2. Use Xcode's Property List Editor (or any other property list editor) to edit the file in your home directory.
  3. Add a new key (child) to the NAT dict. Call it SharingNetworkNumberStart. The type should be String, and the value is the IP network you want to use (eg 10.168.2.0). As an example, here's what my edited file looks like:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    	<key>NAT</key>
    	<dict>
    		<key>AirPort</key>
    		<dict>
    			<key>40BitEncrypt</key>
    			<integer>1</integer>
    			<key>Channel</key>
    			<integer>0</integer>
    			<key>Enabled</key>
    			<integer>0</integer>
    			<key>Extreme</key>
    			<string></string>
    			<key>NetworkName</key>
    			<string>pimpedwifi</string>
    			<key>NetworkPassword</key>
    			<data>################</data>
    		</dict>
    		<key>Enabled</key>
    		<integer>1</integer>
    		<key>PrimaryInterface</key>
    		<dict>
    			<key>Device</key>
    			<string>HUAWEIMobile-Modem</string>
    			<key>Enabled</key>
    			<integer>0</integer>
    			<key>HardwareKey</key>
    			<string></string>
    			<key>PrimaryUserReadable</key>
    			<string>HUAWEI Mobile</string>
    		</dict>
    		<key>PrimaryService</key>
    		<string>C42284CE-6803-42A7-9F54-627DB90321DF</string>
    		<key>SharingDevices</key>
    		<array>
    			<string>en0</string>
    		</array>
    		<key>SharingNetworkNumberStart</key>
    		<string>10.168.2.0</string>
    	</dict>
    </dict>
    </plist>
    
    Save your changes.
  4. Copy the edited file back to the original location. sudo cp ~/com.apple.nat.plist /Library/Preferences/SystemConfiguration/
Now you can (re-)start Internet Sharing, and it will run on your defined subnet. Hopefully some day Apple will add this as a config option in the Sharing System Preferences panel.

[robg adds: You may want to duplicate the original file first, or make sure you have a backup on Time Machine, just in case something goes wrong.]
    •    
  • Currently 2.11 / 5
  You rated: 4 / 5 (9 votes cast)
 
[30,057 views]  

Change the default subnet for Internet Sharing | 11 comments | Create New Account
Click here to return to the 'Change the default subnet for Internet Sharing' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Change the default subnet for Internet Sharing
Authored by: asmeurer on May 13, '09 09:56:21AM

Does anyone know how to set more security options for internet sharing, such as limiting MAC addresses?



[ Reply to This | # ]
Change the default subnet for Internet Sharing
Authored by: harrisj on May 13, '09 04:25:54PM

Thanks for this info. I've not needed to change this yet, but have always wanted to know how to just incase.

Curious to know if anyone reading has ever had to bridge net adapters? Is this even possible in OS X?



[ Reply to This | # ]
Much simpler way to do this, using `defaults` command in Terminal
Authored by: babbage on May 14, '09 02:45:27PM

There's a much, much simpler way to do this, if you don't mind using Terminal for like 15 seconds.

First, paste the following line into Terminal to make a backup, noting that sudo requires your admin password, and won't work on Leopard if your password is blank:

* sudo cp com.apple.nat.plist{,.backup}

Then verify the current setting for the plist file before making any changes:

* defaults read /Library/Preferences/SystemConfiguration/com.apple.nat

(Note that this won't work if you have the full "com.apple.nat.plist", as the defaults command insists on omitting the ".plist" file extension. Blame Apple.)

Then, assert the new setting (this is the only line that actually does anything):

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

Use whatever you find appropriate for that IP address.

Then, confirm the change:

* defaults read /Library/Preferences/SystemConfiguration/com.apple.nat

That's it.

---

--
DO NOT LEAVE IT IS NOT REAL

[ Reply to This | # ]

Much simpler way to do this, using `defaults` command in Terminal
Authored by: daimoh on Jul 23, '09 02:28:07AM

using the "defaults write" stuff worked fine for me, in that it added the relevant line to the file. However, it didn't add it under NAT as the OP mentioned.

So, I used the plist editor that came with XCode, but everytime I restart Internet Sharing, it loses the extra key I put in - it defaults back to what it was before.

How do you make that setting stick?



[ Reply to This | # ]
Much simpler way to do this, using `defaults` command in Terminal
Authored by: ka9lrn on Aug 06, '10 02:14:44AM

I was having the same problem. I found the fix. If the information is in memory when you start/stop Internet Sharing, the file on disk gets written over both when Internet Sharing is started and stopped. I stopped Internet Sharing, changed the file, then rebooted the machine prior to restarting Internet Sharing. After the reboot, it had to get the information from the file. So, the new address information was retained and kept in memory to be written out when it stopped again.

BTW, editing the binary is not necessary. The defaults command worked great with the modified write per Bigtoad. (Don't forget to prepend "sudo" to the example.)



[ Reply to This | # ]
Much simpler way to do this, using `defaults` command in Terminal
Authored by: Bigtoad on Feb 16, '10 08:09:41PM
You got that almost right. A little experimentation showed that this variation worked on 10.6.2:
defaults write /Library/Preferences/SystemConfiguration/com.apple.nat NAT -dict-add SharingNetworkNumberStart 192.168.24.0


[ Reply to This | # ]
Change the default subnet for Internet Sharing
Authored by: Remilio on Jul 26, '09 03:13:15PM

Mmm, I have been looking for this for a long time so I will try it out.

On concern that I have is that I would like to share

en0 Standard Ethernet
through
en1 Airport &
en2 USB ethernet

Any idea how this needs be setup when sharing via 2 interfaces?



[ Reply to This | # ]
Editing the binary
Authored by: paco on Mar 19, '10 05:08:19AM

I struggled with this for a good hour. I'm using 10.6.2 in 64-bit mode (in case that matters). I tried everything suggested: editing the plist file in vi, using the plist editor, using the defaults command, etc. My method was always:
1. turn off Internet Sharing
2. Do my editing
3. turn on Internet Sharing

My results were always the same. It always used 192.168.2.0 for the network. It always overwrote my modified plist file with one that did not include my SharingNetworkNumberStart node. I tried putting that node in various places in the plist. I didn't get any success at all.

Finally, in a fit of frustration, I edited the /usr/libexec/InternetSharing binary. Amazingly, this works:
1. sudo cp /usr/libexec/InternetSharing /usr/libexec/InternetSharing-orig
2. sudo vim /usr/libexec/InternetSharing
3. Search for the string 192 in the binary. You'll find it in 3 places IIRC.
4. In order to keep everything exactly sized correctly, I just changed 192.168.2.0 to 192.168.9.0.
5. Start Internet Sharing in the System Preferences.

It worked. I think it stinks, and if there's an update to OSX, I'll probably have to go do this edit again.



[ Reply to This | # ]
Editing the binary
Authored by: TroyLeeAnderson on Mar 15, '11 09:39:53PM

You were almost there - just add steps 1.5 and 2.5 to get the settings to stick.

1. turn off Internet Sharing
1.5. quit System Preferences
2. do my editing
2.5 relaunch System Preferences
3. turn on Internet Sharing

It seems that System Preferences is cacheing the contents of com.apple.nat.

Now, anyone have any idea how to change the net_ange that the resulting DHCP server serves up from the default of x.x.x.2 - x.x.x.254?



[ Reply to This | # ]
Change the default subnet for Internet Sharing
Authored by: smphoto on Aug 10, '10 06:36:03AM
Each comment is a small piece of the puzzle. To change the subnet used by Airport when internet sharing from a wired ethernet source, the "SharingNetworkStart" key has to placed inside the Airport section of the plist file. See the last key and string in this code snippet.

The previous commenters commands were changing the subnet for the ethernet network interface, not the airport interface. When I finally read the manual in the terminal for internet sharing (man InternetSharing), it says to put the airport subnet starting IP address inside the AirPort section of the plist file.

My office network uses the subnet 10.0.2.0 for its wired network. Internet Sharing over Airport defaults to the same subnet, causing it not to work. The subnet for Internet Sharing has to be unique to prevent conflicts. That's why I changed my Internet Sharing subnet to 10.0.99.0. I can finally use my desktop iMac to share wirelessly to my iPhone and my laptop.

<key>AirPort</key>
		<dict>
			<key>40BitEncrypt</key>
			<integer>0</integer>
			<key>Channel</key>
			<integer>0</integer>
			<key>Enabled</key>
			<integer>1</integer>
			<key>Extreme</key>
			<string></string>
			<key>NetworkName</key>
			<string>imacnet</string>
			<key>NetworkPassword</key>
			<data>cwB0AHUAYQByAA==</data>
			<key>SharingNetworkNumberStart</key>
			<string>10.0.99.0</string>
		</dict>


[ Reply to This | # ]
Change the default subnet for Internet Sharing
Authored by: zeusr on Apr 04, '11 09:49:40AM

Thank you, @smphoto and @TroyLeeAnderson! The combination of where to add it in for AirPort sharing IP change and the VITAL step to CLOSE System Preferences entirely to have the changes stick made my day! Or, well, year as I've been trying to get this done at work since I got my iPad last year on launch day! (I'm a part of IT, so it's allowed. :-)

Again, thank you!



[ Reply to This | # ]