Assign Multiple IP Addresses to Single NIC in Debian 10 - How to do it ?

You can have more than one IP address when using a single Network Card. 

Setting this up is different in each Operating System, but may involve creating a new Network Interface. 

This can look like a unique connection but will be using the same Network Card behind the scenes.

Setting up multiple IP addresses on a single NIC can be required for various reasons like to bind different services to different IP addresses, to host multiple SSL sites, and so on.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to assign multiple IP addresses to a single NIC on their Linux Server.

In this context, we shall look into how to assign multiple IP addresses to a single NIC in Debian system.


How to add Multiple IP Addresses to Single NIC Temporarily on Debian 10 System?

If you are using the Ubuntu OS, you can visit our post on How to assign multiple IP addresses to a single NIC in Ubuntu .

We can add the secondary IP address to the network interface temporarily. 

The IP address added by this method stays until you reboot the system. 

Follow the steps given below to implement this.


1. Before configuring the secondary IP address, you can check the current IP address  of the system by running the following command:

$ ip a
or
$ ifconfig

The output of the "ip a" command  will display the Ip address information.


2. Now, we are going to assign the secondary IP address to it.

To assign a secondary IP address to a NIC, the syntax is as follows:

$ ip adder add <ip-address> dev <interface-name>


3. Now, run the following command to verify if the secondary IP address has been added to the NIC:

$ ip a

In the same way, you can add more IP addresses to your NIC. However, as discussed earlier, these IP addresses are temporary and cannot survive a reboot.


How to remove Multiple IP addresses from NIC ?

There are two ways to remove the additional IP addresses from the NIC. 

The first one is to reboot the system which automatically removes the temporary IP addresses from the NIC. 

However, rebooting a system is not a practical solution. The alternate and the right way is to manually remove the IP addresses using "ip addr del" command.


Here is the command for removing the IP address from the system:

$ sudo ip addr del <ip-address> dev <interface-name>


How to add Multiple IP Addresses to Single NIC Permanently on Debian?

The "ip addr" command temporarily assigns the secondary IP address to a NIC. 

You can also permanently assign the secondary IP address using the interface configuration file so that it remains persistent even if the system is rebooted. Let's see how to do this:


1. Before configuring the secondary IP address, you can check the current IP address  of the system by running the following command:

$ ip a

or

$ ifconfig

This command will display the current or main IP address on our system.

Now we are going to assign the secondary IP address to it.


2. Edit the NIC configuration file as follows:

$ sudo nano /etc/network/interfaces


3. Now, under the current configuration lines, add an entry for the secondary IP address using the following syntax:

iface <interface-name> inet static
address <ip-address>

In the same way, you can add more IP addresses to your NIC. Once you are done with the configurations, save and close the interface configuration file.


4. Now, in order to apply the configuration changes you have made to the interfaces configuration file, restart the networking service as follows:

$ sudo systemctl restart networking.service

On the other hand, you can also apply the configuration changes by bringing down and bringing up the network interface.


To bring down the network interface lets say 'ens37', run the following command:

$ sudo ifdown ens37

Then run the following command to bring it up:

$ sudo ifup ens37

5. Now, run the following command to verify if the secondary IP address has been added to the NIC:

$ ip a


How to remove Multiple IP addresses from NIC on Debian ?

You can also remove the IP address permanently assigned to the network interface.

Follow the steps given below.


1. Edit the interfaces configuration file:

$ sudo nano /etc/network.interfaces

2. Now, remove the additional IP addresses entries you have added to a NIC except for the main IP address. Once you are done, save, and close the file.


3. Now, restart the networking services to apply the configuration changes as follows:

$ sudo systemctl restart networking.service

On the other hand, you can also apply the configuration changes by bringing down and bringing up the network interface.


To bring down the network interface lets say 'ens37', run the following command:

$ sudo ifdown ens37

Then run the following command to bring it up:

$ sudo ifup ens37

4. Now, run the following command to verify if the secondary IP address has been removed to the NIC:

$ ip a


[Need urgent assistance to install missing packages on Debian? We are available to help you. ]

This article covers how to assign and remove multiple IP addresses to and from a single NIC. Based on your preferences, you can either assign the multiple IP addresses temporarily or permanently.

There's no simple command that you can run to determine whether the IP address on a Linux system is assigned by DHCP or static. 

If it changes when the system restarts, it's clearly dynamically assigned, but even a dynamic address has some resistance to change. 

The best way is to look at the configuration file.


To add a static route in Linux:

1. Use the route command with the –p option to add a persistent route: # route -p add default ip-address.

2. Use the route command with the –name option to add a persistent route by specifying a name rather than destination and gateway: # route -p add destination-address gateway-address -name name.


What is ip route command in Linux?

ip route is used to manipulate entries in the kernel routing tables. 

Route types: 

1. unicast - the route entry describes real paths to the destinations covered by the route prefix. 

2. unreachable - these destinations are unreachable. 

Packets are discarded and the ICMP message host unreachable is generated.

Related Posts