IP Aliasing : Assigning multiple IP addresses to single NIC

In this tutorial, we are going to learn to assign multiple IP addresses to a single NIC (Network Interface Card). This process of assigning multiple addresses to a single network interface is called IP aliasing.

Main advantage of using IP aliasing is that we don’t need multiple NICs to configure multiple IPs, hence saving us cost & configuration time. IP aliasing is most useful when using Apache IP based virtual hosting.

For this tutorial, we are going to use RHEL/CentOS 7 but the same process can also be used older versions of RHEL/CentOS, the only change being the name of the network interfaces other than that process is same.

Recommended Read: Top 7 commands for Linux Network Traffic Monitoring

Also Read: Monitoring network bandwidth with iftop command

Network interfaces files in RHEL/CentOS 7(on older versions as well) are located at ‘/etc/sysconfig/network-scripts’ & name of the interfaces are usually ‘ifcfg-en0sX’, where ‘X’ is the number of the interface. In my case, its ‘ifcfg-en0s0’. So we will be using the same for the purpose of this tutorial.

Using Network Manager

We will be using a tool called ‘nmtui’ for this method. NMTUI is command line based user interface for Network Manager & even works for the system that does not have GUI installed. Open terminal & enter the command,

$ nmtui

We will get the following window,

IP aliasing

Click on ‘Edit a connection’, & then select the network interface from the list of interfaces & press ENTER key,

IP aliasing
Now we add the required number of IP address here & once done, we can click on ‘OK’ & then exit from the nmtui menu. Restart the NetworkManager service & we will have our IP aliasing ready.

Manual Method

For this method, we will manually create the necessary files needed. We will assign two different IPs in addition to the one we have already assigned to our interface  ‘ifcfg-en0s0’. To create IP alias, we are going to use our default network interface file & then will create two copies of the file with names ‘ifcfg-en0s0:1‘ & ‘ifcfg-en0s0:2’

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

Now, let’s open primary network interface i.e. eth0, & see its content

$ vi ifcfg-en0s0

DEVICE=”en0s0
BOOTPROTO=static
ONBOOT=yes
TYPE=”Ethernet”
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
HWADDR=32:0A:21:54:ND:6D

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

$ vi ifcfg-en0s0:1

DEVICE=”en0s0:1″
BOOTPROTO=static
ONBOOT=yes
TYPE=”Ethernet”
IPADDR=192.168.1.110
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
HWADDR=32:0A:21:54:ND:6D

& same is to be done for ‘ifcfg:eth0:2’

$ vi ifcfg-en0s0:2

DEVICE=”en0s0:2″
BOOTPROTO=static
ONBOOT=yes
TYPE=”Ethernet”
IPADDR=192.168.1.120
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
HWADDR=32:0A:21:54:ND:6D

Save both files & restart the network service for changes to take effect.

$ systemctl restart network

To check IP addresses have bee assigned or not, run ‘ifconfig’

$ ifconfig

ip aliasing

This completes our tutorial, if you are having any issues/comments, please do mention them in the comment box below.

 

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Become a Supporter – Donate us some of you hard earned money:

Linux TechLab is thankful for your continued support.

Shusain

Passionate about Linux & open source. Loves to learn, read & write about Linux as well as new technologies.

You may also like...

5 Responses

  1. Kitae Kim says:

    hello! how many multiple ip can I assign to 1 NIC ?
    I want assign 500 multiple ip to 1 NIC .

  2. A brief and comprehensive article on IP Aliasing. I advice you to add the procedure of IP Aliasing using Network Manager as well.

  3. Aram Iskenderian says:

    Your manual process applies only for RHEL/CentOS/Fedora based distributions.

    For Debian/Ubuntu based distributions.
    Edit /etc/network/interfaces
    Add the following, change address/netmast/broadcast/network to the ones you’d want to use

    auto eth0:1
    iface eth0:1 inet static
    name Ethernet alias LAN card
    address 192.168.1.7
    netmask 255.255.255.0
    broadcast 192.168.1.255
    network 192.168.1.0

    Then
    ifconfig eth0:0 192.168.1.7 up
    To remove,
    ifconfig eth0:0 192.168.1.7 down
    Then edit /etc/network/interfaces and remove

    Or a much easier and quicker way using ip from iproute2 suite.
    ip addr add 192.168.1.7/24 dev eth0
    To remove
    ip addr del 192.168.1.7/24 dev eth0

    If you are running Ubuntu with netplan installed and enabled, then Interface aliases are not supported , so you can just add a new address in your config file under /etc/netplan.
    For example, if your config is at /etc/netplan/config/yaml, edit it and add a new address under the same interface.

    network:
    version: 2
    renderer: networkd
    ethernets:
    enp3s0:
    addresses:
    – 192.168.1.6/24
    – 192.168.1.7/24
    gateway4: 192.168.1.1

Leave a Reply

Your email address will not be published. Required fields are marked *