Adding additional IPs to Linux

Adding additional IPs to Linux


Using ifconfig

Adding a secondary IP address to a NIC already in use in Linux, and have that change only temporary.

Enter this command:                                                                      

ifconfig [nic]:0 [IP-Address] netmask [mask] up

As example below

ifconfig eth0:0 netmask up

Making sure to be root in order to execute that command.

Using ip command

If you prefer to use the ip command instead of ifconfig

ip address add [ip]/[mask-digits] dev [nic]

As the  example

ip address add dev eth0

With this command you can add more ip address to the same dev NIC.

The second is considered as secondary.


Add a permanent IP address:


For Ubuntu systems, edit the /etc/network/interfaces file

vim /etc/network/interfaces

Add this for one extra IP

auto [NIC]:[n]

iface [NIC]:[n] inet static

address []

gateway []

netmask []

Here an example:

auto eth0:1

iface eth0:1 inet static





You can add as many blocks as you need. by changing eth0:1 for eth0:2, eth0:3 and so on.