A single Network Interface Card (NIC) can be configured with multiple IP addresses. Suppose, you have a web server having multiple domains and each uses SSL, then you need to assign a dedicated IP address for each of the domain. If you have only one ethernet card available in your server, you can make use of the feature called IP aliasing to assign multiple IP addresses on a single NIC card.
In this article, we will go through the temporary and permanent implementation of IP aliasing.
1. Temporarily adding multiple IP addresses on a NIC.
You can use the 'ifconfig' command to add an IP address to a NIC. But, please note that this IP address will not be available after rebooting the machine. So, you need to use the second step for permanently adding the multiple IP addresses. Here, we assume that you already have a NIC with a static IP configured in it. If we need to add two more IP addresses, say 192.168.1.25 and 192.168.1.26 to this interface, we can accomplish this by executing the following commands:
ifconfig eth0:1 192.168.1.25 netmask 255.255.255.0
ifconfig eth0:2 192.168.1.26 netmask 255.255.255.0
2. Permanently implementing IP aliasing.
In order to add multiple IP addresses to a single NIC, we need to modify the configuration files available in the folder '/etc/sysconfig/network-scripts/'.
a. Adding multiple IP addresses.
The configuration for eth0 interface can be found at '/etc/sysconfig/network-scripts/ifcfg-eth0'.
The "DEVICE" mentions the device name. This will be different for each IP alias. The parameter "ONBOOT" specifies whether the IP address should be active on reboots. This should be set to "yes" for automatically activating the IP address during reboot. The parameter "BOOTPROTO" can be static or DHCP. For static IP addresses, it should be set to static. If the IP address is getting allotted dynamically by a DHCP server, this should be set to DHCP. The parameter "IPADDR" parameter should be given with the exact value of static IP address.
In order to add the IP address 192.168.1.25 on this NIC, you need to copy the above file into '/etc/sysconfig/network-scripts/ifcfg-eth0:1' and modify it as follows.
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1
As you can see from the above snippet, we have just modified the fields DEVICE and IPADDR.
Finally, you need to restart 'network' service for the changes to get updated:
service network restart
b. Adding an IP address range.
In order to add a range of IP addresses to eth0 interface, say from 192.168.1.20 to 192.168.1.30, you need to create (update) the file /etc/sysconfig/network-scripts/ifcfg-eth0-range0 with the following data:
Then restart the network service,
service network restart
Now, you will be able to see the configured IP addresses using 'ifconfig' command.