Remotely change static IP via the command line

Jan 21, '05 09:35:00AM

Contributed by: rohanmarr

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.

Comments (14)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050118162423320