IP Aliasing: Assigning multiple IPs to a single NIC

When using IP based hosting to create a website, we require multiple IPs to launch multiple websites on a single apache server. For every website, we will need an IP address assigned to a single NIC or we can use IP aliasing. IP aliasing refers to the process of assigning multiple IPs to single NIC which will help save the cost as we don’t need multiple NICs to assign multiple IPs.

Use cases of IP aliasing can be many, as mentioned above it can used for IP based hosting or we can assign multiple IPs on a single server with each IP having its own function like one IP can host a FTP server. Other can act as a samba or DHCP or DNS server.

Note:- We will be using Centos/RHEL 7 for this tutorial but same process can be used for older versions as well.

 

Configuring Network interface file

We will assign two different IPs in addition to the one we have already assigned to our interface ‘ifcfg-enOs3’. To create IP alias, create two copies of the network interface file located at ‘/etc/sysconfig/network-scripts’ with names ‘ifcfg-enOs3:1‘ & ‘ifcfg-enOs3:2’

$ cd /etc/sysconfig/network-scripts
$ cp ifcfg-enOs3 ifcfg-enOs3:1
$ cp ifcfg-enOs3 ifcfg-enOs3:2

Open the primary interface file i.e.’ifcfg-enOs3’ & view its contents

$ vi ifcfg-enOs3

DEVICE=”enOs3″
BOOTPROTO=static
ONBOOT=yes
TYPE=”Ethernet”
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
HWADDR=62:1B:34:84:HE:9M

We will now configure our other network interfaces, we need to make changes for ‘DEVICE’ & ‘IPADDR’ for aliasing

$ vi ifcfg-enOs3:1

DEVICE=”enOs3:1″
BOOTPROTO=static
ONBOOT=yes
TYPE=”Ethernet”
IPADDR=192.168.1.110
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
HWADDR=62:1B:34:84:HE:9M

Similarly edit the file ‘ifcfg:enOs3:2’

$ vi ifcfg-enOs3:2

DEVICE=”enOs3:2″
BOOTPROTO=static
ONBOOT=yes
TYPE=”Ethernet”
IPADDR=192.168.1.120
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
HWADDR=62:1B:34:84:HE:9M

Save both files & restart the network service for implementing changes made to network

$ systemctl restart network

Once the service has been restarted, we can check IP addresses for the newly created Aliases by running,

$ ifconfig

Similarly we can assign more than two IPs to our NIC.

 

 

Shujat Husain

A continuous learner with several years of experience in linux environment. I love to read, learn & write about Linux & new technologies. And I also write at linuxtechlab.com

What is in your mind, about this post ? Leave a Reply

Close
  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us