12.9. Virtual Hosts

A 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, as seen in this example:

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

Alias entries must start with alias0 using a sequential number such as alias0, alias1, and so on. The configuration process will stop at the first missing number.

The calculation of alias netmasks is important. 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: with a netmask of and with a netmask of The system is to be configured to appear in the ranges through and through Only the first address in a given network range 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 scenario:

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"

All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/

Questions that are not answered by the documentation may be sent to <freebsd-questions@FreeBSD.org>.

Send questions about this document to <freebsd-doc@FreeBSD.org>.