Mac OS X IP Aliases
Different UNIX and UNIX-like OS’s require different semantics when putting an IP alias on an interface. Mac OS X’s are different from Linux or Solaris.
On Mac OS X, be sure to set your primary IP with the correct subnet mask, but each _alias_ needs to have a subnet mask of /32, or 255.255.255.255.
This is because Mac OS X just lumps all the IPs on a given interface together. As a result, when it comes time to pick an outgoing interface, it uses the first one it sees which can reach the default router. This means it may pick an unexpected one.
For example, on Linux, you might have:
eth0: 10.0.0.2 netmask 255.0.0.0
eth0:1 10.0.0.3 netmask 255.0.0.0
And a default route of 10.0.0.1. When a socket is opened to a remote host, Linux will check eth0, eth1, etc. for a route to the default router, and use that interface for the local address (unless the process specifies it).
However, in the same case, Mac OS X would have:
en0: inet 10.0.0.2 netmask 255.0.0.0
en0: inet 10.0.0.3 netmask 255.0.0.0
Because the kernel might change their order, and there’s no way to _specify_ an order, your outgoing connection might come from 10.0.0.2 or it might come from 10.0.0.3. This won’t change over time, but it might change if you add or remove an alias, or you reboot.
The right way to specify an alias on Mac OS X (and this should work on Linux and other OS’s too, but don’t take my word for it), is to ensure that the default router only lives on one interface:
en0: inet 10.0.0.2 netmask 255.0.0.0
en0: inet 10.0.0.3 netmask 255.255.255.255
Now, only 10.0.0.2’s subnet contains 10.0.0.1, so it’s the only address that will be selected for outgoing connections.
A process can still specify a source address of 10.0.0.3, and it’ll work fine. It’s just the default that’s been made deterministic here.
Hey, you’ve resurfaced!
Comment by rone — 2005/6/29 @ 1:47 pm
Yep! I’m alive!
Comment by plambert — 2005/7/4 @ 11:09 am