12.9 Virtual Hosts

A very common use of FreeBSD is virtual site hosting, where one server appears to the network as many servers. This is achieved by assigning multiple network addresses to a single interface.

A given network interface has one “real” address, and may have any number of “alias” addresses. These aliases are normally added by placing alias entries in /etc/rc.conf.

An alias entry for the interface fxp0 looks like:

ifconfig_fxp0_alias0="inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx"

Note that alias entries must start with alias0 and proceed upwards in order, (for example, _alias1, _alias2, and so on). The configuration process will stop at the first missing number.

The calculation of alias netmasks is important, but fortunately quite simple. 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 or 0xffffffff).

For example, consider the case where the fxp0 interface is connected to two networks, the network with a netmask of and the network with a netmask of We want the system to appear at through and at through As noted above, only the first address in a given network range (in this case, and should have a real netmask; all the rest ( through and through must be configured with a netmask of

The following /etc/rc.conf entries configure the adapter correctly for this arrangement:

ifconfig_fxp0="inet netmask"
ifconfig_fxp0_alias0="inet netmask"
ifconfig_fxp0_alias1="inet netmask"
ifconfig_fxp0_alias2="inet netmask"
ifconfig_fxp0_alias3="inet netmask"
ifconfig_fxp0_alias4="inet netmask"
ifconfig_fxp0_alias5="inet netmask"
ifconfig_fxp0_alias6="inet netmask"
ifconfig_fxp0_alias7="inet netmask"