Add an IP Address to Mac OS X Server

There's no GUI interface in Mac OS X Server 10.4 for remotely adding a second IP address to an existing hardware port. Instead, you use the networksetup command line tool. Here's an example.

First, get a list of all active network interfaces:
host:/etc root# networksetup -listallnetworkservices

=> An asterisk (*) denotes that a network service is disabled.
=> Serial Port
=> Built-in Ethernet
=> PCI Ethernet Slot 1
=> Built-in FireWire


I want to add another IP address on the existing built-in ethernet port, so I use the following command:
networksetup -duplicatenetworkservice
              "Built-in Ethernet" "Built-in Ethernet 2"


Now, I need to set the IP settings for the new interface using the -setmanual switch. Here's the format:
networksetup -setmanual <networkservice> <ip> <subnet> <router>

Here's how it might look:
networksetup -setmanual "Built-in Ethernet 2"
               10.1.1.28 255.255.255.224 10.1.1.1



Clearly, you need to change these numbers to suit your actual network. Once the changes are applied, you can check them with -getinfo:
host:/etc root# networksetup -getinfo "Built-in Ethernet 2"

=> Manual Configuration
=> IP address: 10.1.1.28
=> Subnet mask: 255.255.255.224
=> Router: 10.1.1.1


The ifconfig tool exists as well, but it's not completely integrated into the rest of Mac OS X Server. Use networksetup instead.
Design Element
Add an IP Address to Mac OS X Server
Posted Jan 31, 2007 — 5 comments below




 

Nigel Kersten — Jan 31, 07 3471

It's not that ifconfig isn't completely integrated, it's that configd doesn't know about any changes you make via ifconfigd, and so it will just overwrite them on a whim.

I'm not sure what you mean by "no GUI" on OS X Server for this? I tend just "Duplicate" the network interface in the Network pref pane if I've got a GUI session open to my OS X Server boxes...

Scott Stevenson — Jan 31, 07 3472 Scotty the Leopard

It's not that ifconfig isn't completely integrated

I guess we're just splitting hairs, but here's what the official docs say:

However, ifconfig and networksetup do not communicate with each
other. ifconfig changes the network interface settings. [...] If you use ifconfig, your computer will be out of sync and will revert back to the contents of preferences.plist after a restart.


So, basically, it doesn't work its way into the config files.

I'm not sure what you mean by "no GUI" on OS X Server for this

There's no GUI for remotely adding it. You can't use the Server Admin tool, as far as I can tell. If you have phyiscal access to the machine, you can just use System Preferences.

Nigel Kersten — Feb 01, 07 3473

ah. crystal clear what you meant once I actually read the sentence properly... :) My apologies.

Those lines from the official docs are right, but kind of miss the bit that explains why it is so I reckon.

It really does come down to ifconfig not communicating with configd, and so as soon as the Kernel Event Monitor tells configd that things have changed, configd then reverts everything back to the plist. It probably wouldn't be that hard for Apple to patch ifconfig so that it told configd what was going on, but I guess it's just not a priority.

We have an article on this up on afp548.com

You can also use IPAliases ( man IPAliases.conf) on OS X Server to do this for some situations, but it's a bit flakey in my experience and networksetup is a better method.

Nice to see you branching out into some OSXS articles Scott, I've been appreciating your Cocoa work for a fair while now.

Charles — Feb 01, 07 3474

It's been ages since I did this in OSX Server, but I distinctly recall adding an extra IP address to a single ethernet port just using the regular System Preferences>Network stuff, just like you would in OS X Client. This is described in detail in the QuickTime Streaming Server docs. The standard configuration is two IPs on one Ethernet port, you need a second IP address to run the QTSS server over port 80 while your main IP address serves HTTP on port 80.

So.. I don't see why you need to do this through the command line. If you must have a GUI for remotely adding it, use Apple Remote Desktop or VNC and just tunnel into your remote CPU's desktop.

Stefan Seiz — Feb 01, 07 3475

You can also use IPAliases ( man IPAliases.conf) on OS X Server to do this for some situations, but it's a bit flakey in my experience and networksetup is a better method.

Been using IPAliases since ages. Allthough i am still using 10.3.9 Server. Never had a problem with my IP aliases.
Wouldn't like to have 30 or so duplicated network intefaces visible in my Pref Pane (but that is just peronal taste) ;-)




 

Comments Temporarily Disabled

I had to temporarily disable comments due to spam. I'll re-enable them soon.





Copyright © Scott Stevenson 2004-2015