At times, you might have to assign multiple IP addresses to a single Network Interface Card (NIC). The most common use-case of doing so can be that there is more than one network and you want to connect your machine to all of them at a time. In this situation, although, you can get multiple NICs according to your needs, however, a more practical solution will be to assign multiple IP addresses to a single NIC. Therefore, today we will be sharing with you the procedure of assigning multiple IP addresses to a single Network Interface in CentOS 8.

Assigning Multiple IP Addresses to a Single Network Interface on CentOS 8

For assigning multiple IP addresses to a single NIC in CentOS 8, you have to follow the five simple steps that we have described below:

Step # 1: Check the current IP Address of your NIC in CentOS 8

The current IP address of your NIC in CentOS 8 can be checked by executing the following command:

ip addr

Check IP address

The current IP address of our desired NIC in CentOS 8 is “10.0.2.15” as highlighted in the image shown below:

Assigned IP address

Step # 2: View the Contents of the File Containing Information about that NIC in CentOS 8:

Against every NIC in Linux, there is a dedicated file that contains the details about that NIC. For viewing the details of our selected NIC, we will execute the following command:

cat /etc/sysconfig/network-scripts/ifcfg-NIC

Here, you have to replace the word NIC with the name of your particular NIC whose details file you want to view. We have replaced it with “enp0s3”.

View network interface file

The contents of our ifcfg-enp0s3 file are shown in the image below:

Network configuration

An important thing to be taken into consideration over here is that this file might not contain the IP address of that particular NIC as you can see from the image shown above. It is so because only a single IP address is assigned to that NIC at the moment. Therefore, it is not mandatory to mention that IP address in this file unless you assign multiple IP addresses to a single NIC.

Step # 3: Modify that File by Adding Multiple IP Addresses against that NIC in CentOS 8:

Now, we will modify this file by adding multiple IP addresses against our selected NIC. For that, we will open this file by executing the following command:

sudo nano /etc/sysconfig/network-scripts/ifcfg-NIC

Here, you have to replace NIC with the name of your particular NIC whose details file you want to edit. We have replaced it with “enp0s3”.

Edit network config

Now we need to add the default IP address of our particular NIC against the variable IPADDR0 to this file because we are going to assign new IP addresses to it. Moreover, we will also add a new IP address for the same NIC against the variable IPADDR1 say “10.0.2.16”. Both these IP addresses are highlighted in the image shown below:

Add additional IP address

You can even add more than 2 IP addresses against a single NIC in the very same manner against the variables “IPADDR2”, “IPADDR3”, and so on after which you can save and close this file.

Step # 4: Restart your NIC in CentOS 8:

Now, we will restart our NIC so that the new changes can take effect. First, we have to run the following command:

sudo ifdown enp0s3

Shutdown network

This command will deactivate our particular NIC as shown in the image below:

Network stopped

Now, we will run the following command:

sudo ifup enp0s3

Start network

This command will activate our particular NIC as shown in the image below:

Network is up again

Step # 5: Verify if Multiple IP Addresses have been Successfully Assigned to that Particular NIC in CentOS 8 or not:

Once our NIC is restarted, we will run the “ip addr” command once again to see if our newly added IP address has been assigned to our selected NIC or not. You can verify from the highlighted section of the following image that the said operation has been performed successfully.

Check IP addresses

Removing the Additional IP Addresses from a NIC in CentOS 8

Just in case, you want to remove the extra IP address that you have added against an NIC, you can perform the following steps to remove it:

Step # 1: Remove the Additional IP Addresses against a Particular NIC in its Dedicated File in CentOS 8:

We will open the ifcfg-enp0s3 file yet again and simply remove the IP address entries from it as shown in the image below:

Edit network config file

Step # 2: Restart your NIC in CentOS 8:

After doing that, we will restart our NIC by first running the “sudo ifdown enp0s3” command as shown in the following image:

nic down

Then, we will run the “sudo ifup enp0s3” command as shown in the image below:

nic up

Step # 3: Verify if the Additional IP Addresses against your NIC have been Removed or not in CentOS 8:

Finally, we will check if the additional IP address has been removed against our selected NIC or not by running the “ip addr” command once again. You can see from the highlighted section of the following image that now, we only have a single IP address that is also the default one against our selected NIC.

New network config

Conclusion

By following the simple method shared with you in this article, you can conveniently assign as many IP addresses to a selected Network Interface in CentOS 8 as you want. When you are done using the additional IP addresses assigned to a NIC, you can simply remove them by following the removal method.

How to Assign Multiple IP Addresses to a Single Network Interface on CentOS 8
Avatar

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.