Binding multiple IP addresses to a single Ethernet device
In this recipe we will learn how to bind multiple IP addresses to a single Ethernet device in order to provide greater networking functionality to a new or existing CentOS server.
There are many advantages to using a static IP address, but combining this with the ability to use more than one will present you with a new range of configuration options. Clearly, the benefit of circumventing the need to purchase and install multiple Ethernet devices is obvious, but this approach will not only enable you to run multiple servers and websites, it can also enable you to create a private LAN using a local IP and have the alias hold your Internet IP. So with that in mind, it is the purpose of this recipe to show you how easily an IP-rich server can be achieved.
Getting ready
To complete this recipe, you will require a working installation of the CentOS 6 operating system with root privileges and a console-based text editor of your choice. It is assumed that the primary Ethernet device is configured to use a static IP address.
How to do it...
In order to reduce the amount of typing required to complete this recipe, we are going to make a working copy of the original Ethernet configuration files.
- To begin, log in as root and type the following command:
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1
- By doing this, we create a copy of
ifcfg-eth0
and name itifcfg-eth0:1
. You should be aware that the name of this new file is important as it will form the basis of our first virtual device. To proceed, open the virtual configuration file in your favorite text editor by typing:vi /etc/sysconfig/network-scripts/ifcfg-eth0:1
- Scroll down and change the following values:
DEVICE="eth0:1" NAME="System eth0:1"
- Now delete the following line(s):
HWADDR=XX:XX:XX:XX:XX:XX UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
- Finally, you will want to add your new static IP address. To do this, simply scroll down and locate the following line in order to make the relevant changes:
IPADDR=XXX.XXX.XXX.XXX
- When finished, save and close the file and either reboot your server or restart the network settings by typing:
service network restart
- When this process is complete your new network settings will take immediate effect. You can test this by running the following command, which will respond by providing you with an instant report on the current IP address for both
eth0
andeth0:1
.ifconfig
How it works...
In this recipe you have seen how easy it is to create virtual adaptors in order to provide your server with an additional IP address. The ability to increase your IP pool is always welcomed by any server administrator and yes, by using this method you really can enjoy the benefit of an IP-rich environment without the additional expense of new hardware.
So what have we learned from this experience?
Working on the assumption that your Ethernet device was already running a static IP address, we discovered that by making a copy of the original file saves time, and by simply renaming certain values (DEVICE
, NAME
) and removing selected attributes (HWADDR
and UUID
), we can build a virtual adaptor with a separate and wholly distinct IP address with little to no effort.
We completed the recipe by restarting the network in order that CentOS could detect the new settings and automatically include them when the networking service resumes.
You can confirm this by invoking ifconfig
, a console-based command-line utility that will provide you with current feedback on the current state of your Ethernet devices.
So in the end it is hoped that you would agree in saying that this process was very simple, and by taking note of the values given for both eth0
and eth0:1
, you will now be able to reap the benefits of a gain in productivity that will be left for you to explore and enjoy.
There's more...
To add additional adaptors, simply repeat the steps in this recipe and create a new identity for your original Ethernet card using a different label.
Of course, the labels used by each Virtual Adaptor must be unique and they should follow a logical sequence (that is, eth0:1
, eth0:2
, eth0:3
, and so on), but as this recipe has shown, the possibilities are endless and you can use the increased IP range to provide additional services.