While working with computer systems, sometimes you might require multiple IP addresses on your physical machine.
One of the solutions is to have multiple NICs installed on your system.
However, it is not practical to buy a new NIC and plug it in your system when you have the option to assign multiple IP addresses to a single NIC which is referred to as IP Aliasing.
The common use case of IP aliasing is the implementation of IP based virtual hosting.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Ubuntu related Installation tasks.
In this context, we shall look into how to assign multiple IP addresses to a single NIC in Ubuntu OS.
Here, you will learn how to assign a second IP address to a NIC. The second IP address assigned by this method is temporary. Once you reboot the system, it will be removed automatically.
Here are the steps for assigning a second IP address to NIC.
1. First find the current IP address and the name of the interface in your system.
To do so, issue the following command in Terminal:
$ ip addr
The following output shows our network interface is ens33 and the current IP address is 192.168.72.150/24 which is the dynamic IP address assigned by DHCP.
2. Let's assign another IP address to the NIC. To assign an additional IP address to your NIC, issue the following command in Terminal:
$ ip adder add <ip-address> dev <interface-name>
Replace the <ip-address> with the additional IP address you want to assign to your NIC and <interface-name> with the name of your NIC.
For instance, to assign the second IP address 10.1.1.5/8 to your network interface ens33, the command would be:
$ ip addr add 10.1.1.5/8 dev ens33
3. After running the above command, verify if the second IP address has been assigned to your network interface.
Run the following command to do so:
$ ip addr
4. Now try to ping both IP addresses one by one. You will see both IP addresses are reachable:
$ ping 10.1.1.5
In order to remove the additional IP addresses assigned to a NIC, run the following command:
$ sudo ip addr del <ip-address> dev <interface-name>
Replace the <ip-address> with the additional IP address you have assigned to your NIC and <interface-name> with the name of your NIC.
For instance, to remove the IP address 10.1.1.5/8 assigned to our network interface ens33, the command would be:
$ sudo ip addr del 10.1.1.5/8 dev ens33
Earlier we assigned the second IP address using the "ip addr add" command which is not the permanent method.
Once you reboot the system, the IP address removes automatically.
Here, we will see how to make the IP assignment permanent.
In order to assign multiple IP addresses to a single NIC permanently, you will need to configure it in the interfaces configuration file.
i. Edit the interfaces configuration file as follows:
$ sudo nano /etc/network/interfaces
ii. Then, Append the following lines in the file:
iface <interface-name> inet static
address <ip-address>address
Replace the <interface-name> with the name of your NIC to which you want to assign the additional IP address and <ip-address> with the IP address, you want to assign.
For instance, to assign the second IP address 10.1.1.5/8 to your network interface ens33, the lines would be changed to:
iface ens33 inet static
address 10.1.1.5/8
iii. Once you have added the above lines, save, and close the file.
iv. Now restart the networking service to apply the configuration changes you have made above:
$ sudo systemctl restart networking
Alternatively, bring down and bring up the interface to apply the changes:
$ sudo ifdown ens33
$ sudo ifup ens33
v. Now to verify if the additional IP address has assigned to the network interface, use the following command:
$ ip addr
As we have configured the additional IP address in the configuration file, therefore it will remain permanent even if you reboot the system.
You can also remove the additional IP address you have configured in the interfaces configuration file.
i. To do so, simply edit the /etc/network/interfaces file and remove the entry for the additional IP addresses you have added.
ii. Then save and close the file and restart the networking services:
$ sudo systemctl restart networking
or bring down and bring up the interface to apply the changes:
$ sudo ifdown ens33
$ sudo ifup ens33
This article will guide you on how to assign multiple IP addresses to a single NIC in Ubuntu OS. Now you can allocate multiple IP addresses to a single NIC.
To change your IP address on #Linux, use the "ifconfig" command followed by the name of your network interface and the new IP #address to be changed on your computer.
To assign the subnet mask, you can either add a "netmask" clause followed by the subnet mask or use the CIDR notation directly.
The ifconfig command can be used from the #command line either to assign an address to a #network interface or to configure or display the current network interface configuration information.
The ifconfig command must be used at system startup to define the network address of each interface present on a machine.
To determine my IP address in Linux :
1. ifconfig -a.
2. ip addr (ip a).
3. hostname -I | awk '{print $1}'.
4. ip route get 1.2.
5. nmcli -p device show.
To add secondary IP address permanently on Ubuntu system, just edit /etc/network/interfaces file and add the requires IP details.
Verify the newly added IP address. # ifconfig eth0