How to add an additional IP in Debian or Ubuntu

View Current Network Settings

Before we start, lets take a look at the current settings.

cat /etc/network/interfaces
auto eth0
iface eth0 inet static
address 123.34.45.56
netmask 255.255.255.0
gateway 123.34.45.1
hwaddress 00:12:34:56:78:9A
dns-nameservers 69.64.66.11 69.64.66.10

auto lo
iface lo inet loopback

 

Configure Updated Settings

Before proceeding, a couple of variables need to be defined.

EthX:1 = The interface your IP is connected to. If your current IP is set with auto eth0, you will use eth0:1. If your current IP is set with auto eth1, you will need to use eth1:1.
IpAddress = The IP address you are adding to your server.
GatewayIP = The IP address you are adding to your server, but replace the last octet with 1. Example: if your IP address is 123.45.67.89, then gatewayIP = 123.45.67.1

 
Using the variable defined above, you are ready to configure the network adaptor to use your new IP and gateway. Use the nano editor which comes installed by default with Ubuntu and add the following lines underneath dns-nameservers.

sudo nano /etc/network/interfaces
auto EthX:1
iface EthX:1 inet static 
address IpAddress
netmask 255.255.255.0 
gateway GatewayIP

Once you have entered the values correctly, press Ctrl+Enter to save it with the current filename, then press Ctrl+X to exit the editor.

Provided you entered your values correctly, verify the new settings by retyping the cat command:

cat /etc/network/interfaces
auto eth0
iface eth0 inet static 
address 123.34.45.56
netmask 255.255.255.0 
gateway 123.34.45.1 
dns-nameservers 69.64.66.11 69.64.66.10

auto eth0:1
iface eth0:1 inet static 
address 123.45.67.89
netmask 255.255.255.0 
gateway 123.45.67.1

auto lo
iface lo inet loopback

 

Apply setting to Interface

After you have determined the values entered are correct, restart networking with the following command:

sudo service networking restart
stop: Unknown instance: 
networking stop/waiting
administrator@ubuntu:~#

 

Finish

Your IP should now be working correctly.

Comments

So empty here ... leave a comment!

Leave a Reply

Sidebar