Freebsd – Why is it necessary to set a netmask of 255.255.255.255 for “alias” addresses in FreeBSD

aliasfreebsdinterfacenetworking

From FreeBSD handbook on the topic of virtual hosts:

For a given interface, there must be
one address which correctly represents
the network's netmask. Any other
addresses which fall within this
network must have a netmask of all 1s
(expressed as either 255.255.255.255
or 0xffffffff).

Can anybody explain why this is the case?

Best Answer

This page contains a good explanation imho:

Since aliases are, in a sense, duplicate tags, the system needs to know whether the subnet represented by the tag is new, and this is indicated by the netmask. With a "normal" netmask, the system is told this is a new subnet, and it can then set up internal tables correctly. If the subnet is not new, the tables will get set up incorrectly if the netmask is "normal".

With a netmask of 255.255.255.255, the system knows this is a duplicate of an existing subnet, and therefore will assign the address as if it were assigned to the loopback interface, with the "point-to-point" mask.

Assigning a netmask of 255.255.255.0 will, in most cases, appear to work. However, the internal tables will not be set up correctly, and if the alias is removed, problems may ensue. This can be overcome by adding appropriate host routes when the alias is added, and removing the routes when the alias is removed. However, the system works correctly with the "point-to-point" netmask, and maintenance is easier.