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

Remotely change static IP via the command line Network
I manage multiple webservers in both a live and test environment, and often set up a machine with a 'test' IP. Once testing is completed, I need to swap out the 'live' IP with the 'test' IP. This has become more interesting since I now have a mix of both OS X Client and OS X Server boxes. OS X Server provides some CLI tools for this purpose called changeip and networksetup. However, I find them more laborious than the method I use on the Client version. Read on for my solution...

I simply find and edit /Library -> Preferences -> SystemConfiguration -> preferences.plist (I always make a backup just in case).

If you are using a static IP (assuming IPv4) you should see something like this:
<key>IPv4</key>
  <dict>
    <key>Addresses</key>
      <array>
        <string>192.168.1.99</string>
      </array>
    <key>ConfigMethod</key>
      <string>Manual</string>
    <key>Router</key>
      <string>192.168.1.1</string>
    <key>SubnetMasks</key>
      <array>
        <string>255.255.255.0</string>
      </array>
  </dict>
You simply edit the value <string>192.168.1.99</string> in this case and reboot. With OS X Server, I also take the extra step of running changeip, since it looks like it changes Open Directory settings and this hack only changes the Network interface settings of the host:
[host:~] root# changeip - 192.168.1.99 192.168.1.98
Updating local node
Updating Password Server config
Updating Open Directory config
Updating hostconfig file
This may be obvious, but I hope this is useful since I haven't found this posted in a quick search. Also, this works Jaguar (for Mac OS X 10.2.8 or earlier). Just look for the file in /var -> db -> SystemConfiguration -> preferences.xml.
    •    
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[21,690 views]  

Remotely change static IP via the command line | 14 comments | Create New Account
Click here to return to the 'Remotely change static IP via the command line' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Don't reboot...
Authored by: sharumpe on Jan 21, '05 11:32:29AM

Rather than rebooting just to change an IP, why don't you use ifconfig?

> sudo ifconfig en0 inet xxx.xxx.xxx.xxx

On most Macs, en0 is your default ethernet interface. If you're using another interface, specify that instead. This will go away, of course, the next time you reboot, but if you do whatever you like from your instructions above, the next reboot will catch the new IP, too.



[ Reply to This | # ]
Don't reboot...
Authored by: csdk0713 on Jan 21, '05 12:43:23PM

I would agree that a reboot is optional. But I would suggest that it's probably a good idea to reboot now, during configuration. If you have to reboot at a later date when the system is "in production", and your system does not come up on the expected IP, or there's a typo in the default route or something, that could cause a bigger problem.



[ Reply to This | # ]
Don't reboot...
Authored by: lolopb on Jan 21, '05 02:00:26PM

Just because ifconfig, although it's a legacy tool, doesn't respect Mac OS X procedure when changing things, for example configd is not aware of your changes and preferences.plist (located in "/Library/Preferences/SystemConfiguration") is not updated.

Check this :

http://developer.apple.com/documentation/Networking/Conceptual/SystemConfigFrameworks/SC_Components/chapter_3_section_5.html



[ Reply to This | # ]
Don't reboot...
Authored by: csdk0713 on Jan 21, '05 02:24:52PM

You touched a nerve and I had to respond.

ifconfig is not a "legacy" anything. This is what actually does the work behind the scenes.

Furthermore..."legacy" is a marketing term. If a command/utility is being phased out or should not be used, the correct term would be "deprecated", NOT legacy. ifconfig is neither.



[ Reply to This | # ]
Don't reboot...
Authored by: peragrin on Jan 21, '05 03:43:07PM

Evedience of ifconfig usefulness is of all people MSFT.

Windows until 2000 had winIPcfg a gui program. win2k, win xp, win2k3, etc includes a commandline program called ipconfig. It works very similar to ifconfig.

Also note that Longtooth is supposed to include a proper commandline and shell called MSH. If command line programs are legacy then why is MSFT just now impleneting it as a feature.

---
I thought once I was found but it was only a dream



[ Reply to This | # ]
Don't reboot...
Authored by: kchrist on Jan 22, '05 11:25:30AM
Not to get too far off topic here, but ipconfig has been around forever. It's been around at least as long as Windows NT 3.5, which was released in 1994, and I'm pretty sure it existed before that in Windows for Workgroups/DOS.

Anyway, it can't really be compared to ifconfig on Unix, as you can't use it to actually do anything other than release/renew DHCP leases. It's mostly just for displaying network information, where ifconfig does all the real work of modifying interface configuration (hence the name!).

[ Reply to This | # ]
Don't reboot...
Authored by: lolopb on Jan 23, '05 04:33:29PM

You may consider whatever you want but using ifconfig only is not recommended by Apple as it doesn't inform all the frameworks of the changes made. If it was the good tool why would Apple develop tools that you can find in Mac OS X Server to change network configuration ?

If you want to consider ifconfig is your tool, make it your way, I don't mind at all, but I don't recommend it, that's all, just as Apple does itself...

I use ifocnfig only for reading things about my config, never to modify it. And yes I consider it as a legacy tool as many unix users expect to find it although it has lost most of its interest as Apple developped a much more interesting system to manipulate network configurations.



[ Reply to This | # ]
Don't reboot...
Authored by: jesboat on Jan 23, '05 08:49:29PM

It's called high-level vs low-level. ifconfig is a low-level tool - pretty much all it does it tell you the current state of a network device or change the state of the device. It doesn't send out notifications, update configd, or do anything else, because it doesn't need to.

configd is a program that is higher-level. It interacts with many parts of the operating system, but, when it's time to change the actual IP address of the card, configd and friends just call ifconfig to do the dirtywork.

Apple wrote configd and such in order to create an easier way to use ifconfig (and its friends, arp, route, etc.) than opening up a Terminal window and running ifconfig directly, not to re-invent what ifconfig does.

---
--
With no walls or fences on the 'net, who needs Windows or Gates?



[ Reply to This | # ]
Don't reboot...
Authored by: lolopb on Jan 24, '05 01:24:29AM

Reading this :

<http://developer.apple.com/documentation/Networking/Conceptual/SystemConfigFrameworks/index.html?http://developer.apple.com/documentation/Networking/Conceptual/SystemConfigFrameworks/SC_Intro/chapter_1_section_1.html#//apple_ref/doc/uid/TP40001065-CH201>

I'm not that sure that ip agents used by Apple is ifconfig, it's not pretty clear at all.

I agree that configd is higher-level thant ifconfig but, again according to that document, the work done whenever you click on the "Apply" button in your Network Preference Pane (or whenever you switch from a net config to another) is a little bit more complex than just launching ifconfig.

Again, do what you want, I don't mind, but don't be surprised if what you set from ifconfig is changed by configd, which can happen, sometimes...



[ Reply to This | # ]
regarding ifconfig and rebooting
Authored by: webbix on Jan 21, '05 03:32:07PM

I would also think 'ifconfig' is the way to go on this. I speculate that the only way the change in the preference.plist would activate is via a reboot. There is no doubt that you can change the IP without rebooting.

I use various location settings on my TiBook and prefer to sleep it to 'refresh' all apps as some things (mail, remote control apps, etc) get confused. However, this seems much less an issue these days.

I would think a reboot would be more critical on an OS X server as it is picky about having nameservice running and configured. So, changing the IP may mean that it does not gracefully reconfigure the host name.



[ Reply to This | # ]
Much simpler way - doesn't need reboot
Authored by: kholburn on Jan 22, '05 05:30:18PM

There's a much simpler way. You set up 2 locations, one with each IP you want. Use the command "scselect" to change locations.



[ Reply to This | # ]
Remotely change static IP via the command line
Authored by: dreness on Jan 23, '05 03:21:34AM
Here's how it breaks down:
  • ipconfig is not related to the Windows utility, it just happens to have the same name. ipconfig in OS X is a semi-undocumented tool provided with both client and server. It changes interface configurations using the System Configuration framework, which means that configd is involved and any changes are persistant. Experiment with ipconfig set en0 MANUAL or ipconfig set en0 DHCP for example. It is perfectly okay to use ipconfig in os x or os x server (though with server don't forget about changeip also)
  • ifconfig exists in os x and behaves as it would on other platforms. However, changes made via ifconfig do not go through configd. Not only are changes made via ifconfig not persistant, but they may be overwritten by configd any time it detects a network change. Therefore, it is not advisable to use ifconfig in OS X for anything other than displaying network interface settings.


  • [ Reply to This | # ]
Remotely change static IP via the command line
Authored by: kholburn on Jan 23, '05 08:25:49PM
nice

$ man ipconfig
No manual entry for ipconfig
$ ipconfig --help
usage: ipconfig <command> <args>
where <command> is one of waitall, getifaddr, ifcount, getoption, getpacket, set
$ ipconfig set --help
usage: set  <interface name> < BOOTP | MANUAL | DHCP | INFORM | NONE > <method args>
$ ipconfig set en0 MANUAL --help
usage: ipconfig set en0 MANUAL <ip> <mask>



[ Reply to This | # ]
Remotely change static IP via the command line
Authored by: jzhao on Jan 25, '05 02:21:06PM

I ran into a similar situation as the original poster.

I need to assign static IP address with shell script. I tried ipconfig. It only works half way. The change was propagated by configd. I can see that in system.log. But it didn't get kept. The file /Library/Preferences/SystemConfiguration/preferences.plist was not modified. The old setting came back on reboot.

What I did is: sudo ipconfig set en0 MANUAL 192.168.1.66 255.255.0.0

What else do I need? hanks in advance.



[ Reply to This | # ]