Adding Virtual Network Interfaces on CentOS 5.x

Posted by Warren Selby on Oct 4, 2009 in Blog, linux | 0 comments

Recently at a client, I found myself consolidating two servers into one. Each server hosted their own array of services, a few of which overlapped. The first server was running a TFTP server, an HTTP web server, and an NTP time server. The second server, which would be the target server of the consolidation, was running it’s own TFTP server, an FTP server, and a DHCP server. The first thought was to reconfigure all of the clients that pointed at the first server’s IP address and point them to the second server’s IP address, but that would involve reconfiguring over 150 IP phones across two floors, most of which would have to be done by hand. Realizing that this wasn’t a very good option, I started looking for another solution.

In comes the idea of Virtual Network Interfaces, or assigning multiple IP addresses to the same physical interface. On Windows this is a pretty simple task, you just right-click the network interface, go to properties, go to the TCP/IP properties for your interface and then click Advanced – you’ll be given the option to add additional IP’s on the first screen. On a console-based Linux server, the approach is different, but still rather simple. In my example, the client was running a CentOS 5.3 server, but this will apply across many different Linux variants.

First you need to copy the file /etc/sysconfig/network-scripts/ifconfig-eth0 to /etc/sysconfig/network-scripts/ifconfig-eth0:1.

# cd /etc/sysconfig/network-scripts/
# cp ifconfig-eth0 ifconfig-eth0:1

Next, you need to open the new file (/etc/sysconfig/network-scripts/ifconfig-eth0:1) and change the #FILE, DEVICE, and IPADDR settings:

# File: ifcfg-eth0:1
DEVICE=eth0:1
ONBOOT=yes
BOOTPROTO=static
IPADDR=10.10.11.254
NETMASK=255.255.255.0
BROADCAST=10.10.11.255
NETWORK=10.10.11.0
HWADDR=00:80:48:8A:33:A3

Finally, you’ll need to restart your network service. Don’t worry if you’re doing this remotely, as long as you haven’t changed the settings for your original network file, you’re interface should come back up within a few seconds. Your terminal session may hang while the NIC reloads itself, but after that it will come back just fine.

# service network restart

That’s it!  If you’re consolidating two servers, like I was, you’ll want to make sure you take the old server off the network before you restart your network service or else you’ll have an IP address conflict on your hands, and nobody wants that!

Leave a Reply