How to add a secondary IP to Linux

Add a secondary IP to Linux

Add a second temporary IP address

Using ifconfig

If you want to add 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

An example is shown below

ifconfig eth0:0 192.168.1.2 netmask 255.255.255.0 up

You need 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]

Here is an example

ip address add 192.168.99.37/24 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

Ubuntu

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 [ip.add.rr.ss]
gateway [gw.ip.ad.rs]
netmask [ne.tm.as.kk]

Here an example:

auto eth0:1
iface eth0:1 inet static
address 192.168.0.1
gateway 192.168.0.254
netmask 255.255.255.0

You can add as many blocks as you want. Just change eth0:1 for eth0:2, eth0:3 and so on.

If you are adding additional IPs to eth1, or eth2 also modify that on the example.

  • 90 Users Found This Useful
Was this answer helpful?

Related Articles

Port 25 unblock

Port 25 in VCCLHOSTING  is blocked by default. If you need to send out email , you can follow...

Setup Exim to Send Email Using Gmail in Debian

Setup Exim to Send Email Using Gmail in Debian Install Exim4 apt-get install exim4...

How to Secure FreeBSD with PF Firewall

This tutorial will show you how to protect your FreeBSD server using OpenBSD PF firewall. We will...

Configuring IPv6 on your VPS

All these examples assume an IPv6 subnet of 2001:DB8:1000::/64. You'll need to update them with...

Add a Secondary IPv4 Address to Your VPS

This tutorial explains how to setup an additional IPv4 address on your KVM VPS. We will assume...