How to assign multiple IP addresses to one network interface in CentOS 8

Sometimes you may need to assign multiple IP addresses to a single Network Interface Card (NIC). The most common use case for this might be that there is more than one network and you want to connect your computer to all of them at the same time. Although in this situation you can get multiple network adapters according to your needs, it is more practical to assign multiple IP addresses to one network adapter. Therefore, today we will share with you the procedure for assigning multiple IP addresses to one network interface in CentOS 8.

Assigning Multiple IP Addresses to One Network Interface in CentOS 8

To assign multiple IP addresses to a single network adapter in CentOS 8, you need to follow five simple steps, which we described below:

Step # 1: check the current IP address of your network card in CentOS 8

The current IP address of your network card in CentOS 8 can be checked by running the following command:

ip addr

The current IP address of the desired network card in CentOS 8 is “10.0.2.15” as shown in the image below:

Assigned IP address

Step # 2: View the contents of the file containing information about this network card in CentOS 8:

For every network card in Linux, there is a special file that contains detailed information about that network card. To view information about the selected network card we will run the following command:

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

Here, you must replace the word NIC with the name of your specific NIC whose info file you want to view. We replaced it with “enp0s3”.

View the network interface file

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

Network configuration

The important thing to keep in mind here is that this file may not contain the IP address of that particular network card, as you can see in the image above. This is because there is currently only one IP address assigned to this NIC. Therefore, it is not necessary to specify this IP address in this file, unless you have assigned multiple IP addresses to the same network card.

Step # 3: Modify this file by adding some IP addresses for this network adapter in CentOS 8:

We will now modify this file to add some IP addresses for our selected network card. To do this, we will open this file by running the following command:

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

Here you must replace the NIC with the name of your specific NIC whose info file you want to edit. We replaced it with “enp0s3”.

Change network configuration

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

Add an additional IP address

You can even add more than two IP addresses to the same network adapter in the same way regarding the variables “IPADDR2”, “IPADDR3” and so on, after which you can save and close this file.

Step # 4: Reboot the network adapter in CentOS 8:

We will now restart our NIC for the new changes to take effect. First, we must run the following command:

sudo ifdown enp0s3

Turn off the network

This command will disable our specific NIC as shown in the image below:

The network is stopped

We will now run the following command:

sudo ifup enp0s3

Start network

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

The network is working again

Step # 5: Make sure multiple IP addresses have been successfully assigned to this particular NIC in CentOS 8 or not:

After restarting our network adapter, we will run the “ip addr” command again to see if our newly added IP address has been assigned to the selected network adapter or not. You can check from the highlighted section of the following image that the specified operation was completed successfully.

Check IP Addresses

Removing Additional IP Addresses from Network Card in CentOS 8

Just in case, if you want to remove the additional IP that you added for the network card, you can follow these steps to remove it:

Step # 1: Remove additional IP addresses for a specific network card in its dedicated file on CentOS 8:

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

Edit network configuration file

Step # 2: Reboot the network adapter in CentOS 8:

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

nick down

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

pleasant

Step # 3: Check if the additional IP addresses of your network adapter have been removed in CentOS 8:

Finally, we will check if the additional IP address for our selected network card has been removed by re-running the “ip addr” command. From the highlighted section of the next image, you can see that we now only have one IP address, which is also the default address for our selected network card.

New network configuration

Conclusion

By following the simple method outlined in this article, you can easily assign as many IP addresses to a selected network interface in CentOS 8 as you like. When you are done using the additional IP addresses assigned to the network card, you can simply remove them by following the removal method.

How to assign multiple IP addresses to one network interface in CentOS 8

Sidebar