Sometimes we have to host multiple websites, but we have a single server, so how can we make it possible to host them on one server? We can make a virtual server by assigning different IPs (Internet Protocols) to a single NIC (Network Interface Card) and can host multiple IP addresses. We do this to host multiple IPs because it is not possible to buy different NICs to host IPs individually.
We are working in an office where we have three networks, and we want to connect them using a single NIC. Then, we will follow the steps which are going to be discussed in the next sections of this write-up to assign multiple IP addresses to a single NIC in Ubuntu.
What is a method to assign multiple IP addresses to a single NIC in Ubuntu using the Command-line method
There is a very simple method to assign two IP addresses using a single NIC using the terminal of Ubuntu, first we will find out the ip address of our machine using the command:
$ ip a
In the above output, we can see that in the title of “enp0s3”, we can see the current IP address of our machine is “10.0.2.15/24” which is a dynamic IP address assigned by DHCP, so now, we will assign a second IP address to our machine using the command below:
$ sudo ip addr add 10.1.5.20/8 dev enp0s3
In the above command, we used the option “add” to assign another IP address to the dev enp0s3 to verify the IP address is assigned, we will use the command:
$ ip a
We can clearly see that the two IP addresses have been assigned to our machine, now to confirm the authentication of both IP addresses, we will ping both of them using the ping command one by one:
$ ping 10.0.2.15
$ ping 10.1.5.20
Likewise, we can assign more than two IP addresses to our NIC.
How to remove the temporary assigned IP address on Ubuntu
The way by which added the second IP address, following the same, just replacing the option “add” with “del”, we can remove the added IP address, for example, in our case, we will use the command:
$ sudo ip addr del 10.1.5.20/8 dev enp0s3
To confirm the removal of IP address, we will use the command:
$ ip a
The IP address has been removed successfully.
IP addresses are used to connect with the different computers on the same networks or to visit different websites, and sometimes we need to connect to more than two servers for which we are supposed to have separate NICs which are not practical, so we used the single NIC to connect with two servers and in this guide, we have discovered the method of assigning multiple IP addresses Ubuntu to a single NIC by finding out the IP address and then adding the other IP address as well and also learn the method of removing it.
The Best Linux Tutorials Website