Virtual Network Interfaces and Dependent Web Sites
Kailash Jayaswal
It is not uncommon for UNIX servers to have more than one network interface adapter, each with its own IP address and hostname. There are advantages to having a system respond to several IP addresses, but cost and number of available slots limit the number of network cards that can be installed in a system. Yet, you may have a genuine need to assign several hostnames and IP addresses to a system.
Several UNIX implementations provide ways to set up "virtual interfaces" for a single "physical network interface". Each virtual interface, like a physical one, would have a unique IP address and a fully qualified hostname. I will look at the advantages of assigning several IP addresses and hostnames to a single physical network interface and outline the steps involved in configuration.
The primary advantage to this setup is the absence of any need to buy or install new network adapters. The steps to configure "virtual interfaces" are simple, and new hostnames can be put in existing or new DNS domains. These fully qualified hostnames can be used as Web site URLs. A system known as: www1.dept1.gadgets.com as well as www2.dept2.gadgets.com can be used to serve two Web sites (namely, http://www1.dept1.gadgets.com/ and http://www2.dept2.gadgets.com/). In this case, the hostnames (www1 and www2) are different. The domain names (dept1.gadgets.com and dept2.gadgets.com) are also different, yet both use the same network interface adapter.
Among the hostnames that a system can have, there is one primary (or default) node name, specified in a platform-dependent text file. Solaris uses /etc/nodename; HP-UX uses /etc/rc.config.d/netconf file; and IRIX uses /etc/sys_id to specify primary system name. The default DNS domain name for the system is specified in /etc/resolv.conf.
In this article, I will use a Solaris example to outline the steps required to set up a virtual interface. The physical device name for the first Ethernet interface is le0, and nf0 for the first FDDI interface. Corresponding virtual interfaces would be le0:1, le0:2, le0:3,... and nf0:1, nf0:2, nf0:3,.... A new file must be created for each interface. The filename reflects the interface for which it is used (e.g., /etc/hostname.le0:1 file contains the hostname related to the the first virtual interface for le0).
# cat /etc/hostname.le0:1
www1
For FDDI, the filename would be /etc/hostname.nf0:1. You can have up to 255 virtual interfaces per physical interface. You can therefore go up to /etc/hostname.le0:255 or /etc/hostname.nf0:255. All new hostnames and IP addresses must be specified in /etc/hosts. The new virtual interface can be defined using ifconfig:
# ifconfig <interface>:<number> <IP address> \
netmask <netmask number e.g. 255.255.255.0> \
broadcast <subnet broadcast IP address>
where the physical interface is le0, le1..., nf0, nf1,... and the number after the colon is the logical interface number. The IP address is the one designated for this virtual interface. Your network may use a netmask number other than 255.255.255.0.
To enable the interface, type:
# ifconfig le0:1 up
The two ifconfig statements can be combined. The above steps can be repeated for all logical interfaces. To verify that the system responds to all IP addresses and hostnames, you can use ping, ifconfig -a or netstat -i.
$ ifconfig -a
lo0: flags=849<UP,LOOPBACK,RUNNING,MULTICAST> mtu 8232
inet 127.0.0.1 netmask ff000000
le0: flags=863<UP,BROADCAST,NOTRAILERS,RUNNING,MULTICAST> mtu 1500
inet 143.132.121.20 netmask ffffff00 broadcast \
143.132.121.255
ether 8:0:20:12:65:d6
le0:1:flags=843<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 143.132.193.159 netmask ffffff00 broadcast \
143.132.193.255
netstat shows the number of collision and error packets in relation to the total number of input and output packets:
$ netstat -i
Name Mtu Net/Dest Address Ipkts
Ierrs Opkts Oerrs Collis Queue
lo0 8232 127.0.0.0 localhost 1293
0 1293 0 0 0
le0 1500 143.132.121.0 www1.dept1.gadgets.com 88892 0 87065
4 6044 0
le0:1 1500 143.132.193.0 143.132.193.159 0 0
0 0 0 0
To start the virtual interfaces during system bootup, the required ifconfig commands must be placed in a proper bootup script (e.g., in file /etc/rc2.d/S92virtualint). If this is a new file, make sure it has execute permissions.
For IRIX 6.x systems, configuring multiple IP addresses for a physical interface is supported through IP aliasing. Besides adding new hostnames and IP addresses in /etc/hosts and running ifconfig commands as outlined above, you must edit the /etc/config/ipalias.options file to add a line for each new logical interface (i.e., IP address) as follows:
<logical interface> <new IP address> netmask <value> broadcast <value>
ec0:1 125.143.181.169 netmask 255.255.255.0 broadcast 125.143.181.255
where ec0:1 is the first logical interface with IP address 125.143.181.169 configured for the Ethernet controller. The IP address can be substituted for its fully qualified hostname. The following command must be run in order to create /etc/config/ipaliases and enable IP aliasing when the system is rebooted:
# /etc/chkconfig -f ipaliases on
The new IP addresses and hostnames can be put in separate or same domains. If you wish to use a new DNS domain name, it must first be created within DNS.
Web Sites Based on Virtual Network Interface Hostnames Web sites with unique URL addresses can be set up with any Web server software such as Netscape Enterprise server. Each URL requires a unique fully qualified hostname. A system with many virtual interfaces will respond to all fully qualified hostnames configured for that system and can therefore be the server for several unrelated URL sites. Each URL site may have its own root HTML directory, server root directory, log files, httpd UNIX processes and configuration files, such as magnus.conf, obj.conf, etc. used by Netscape servers.
Network or Web administrators can set up multiple Web sites on a single host with Web addresses that do not use the primary host or domain name. And, you do not have to spend a fortune for this. The obvious drawback, however, is that traffic for the Web sites goes through the same network card, creating a potential bottleneck. If you employ this method, you will want to monitor traffic levels and adjust your configuration as the need arises. n
About the Author
Kailash Jayaswal has been administering UNIX systems and Internet servers for the last 6 years. He is currently working as a consultant at the Storage Systems Division of IBM, in San Jose. He can be reached by email at: jayaswal@astralray.com.
|