In this post, we will be demonstrating you how to assign multiple IP addresses to a single NIC in Ubuntu OS. We will be demonstrating the procedure on Ubuntu 20.04 (Focal Fossa).
Assigning Multiple IP Addresses to Single NIC Temporarily
In the following section, we will see 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:
The following output shows our network interface is ens33 and the current IP address is 192.168.72.157/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:
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:
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:
Here is the output of the above command which shows two IP addresses assigned to the ens33 network interface.
4. Now try to ping both IP addresses one by one. You can see both IP addresses are reachable.
Remove the Multiple IP addresses from NIC
In order to remove the additional IP addresses assigned to a NIC, run the following command:
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:
Assigning Multiple IP Addresses to Single NIC Permanently
In the previous section, we have 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. In this section, 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.
1. Edit the interfaces configuration file as follows:
Append the following lines in the file:
address <ip-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:
address 10.1.1.5/8
Once you have added the above lines, save, and close the file.
Now restart the networking service to apply the configuration changes you have made above:
Alternatively, bring down and bring up the interface to apply the changes:
$ sudo ifup ens33
Now to verify if the additional IP address has assigned to the network interface, use the following command:
As we have configured the additional IP address in the configuration file, therefore it will remain permanent even if you reboot the system.
Remove the Multiple IP addresses from NIC
You can also remove the additional IP address you have configured in the interfaces configuration file. To do so, simply edit the /etc/network/interfaces file and remove the entry for the additional IP addresses you have added. Then save and close the file and restart the networking services:
or bring down and bring up the interface to apply the changes
$ sudo ifup ens33
This is how you can assign multiple IP addresses to a single NIC in Ubuntu OS. In this post, we have discussed both the temporary and permanent methods for assigning the secondary IP address to a single NIC. Following the same methods, you can allocate multiple IP addresses to a single NIC.
from Linux Hint https://ift.tt/3vaCdBc
0 Comments