Add an Additional IP Address (CentOS/Debian)

Posted
Comments 1

There are a lot of reasons you may want to add an additional IP under your Linux dedicated or VPS server. In most cases your hosting provider shall be able to allocate and route additional IP address on request. When you request a new IP it’s quite possible to be asked about the purpose you’re going to use it for, known as justification. Additional IPs will cost you a couple of more bucks and the price depends from provider to provider. Once your request is accepted the IP will be routed to your server and you’re ready to go. Now you have to configure the new IP under your linux box. Depending on the linux distribution used the steps are slightly different.

For both Debian and CentOS you have to define network interface aliases.

Debian

Under Debian edit your /etc/network/interfaces file and add a code block like the one below containing the alias, the IP address and the netmask. Note you cannot specify gateway and dns-nameservers for an alias. The example below adds an IP address with alias eth0:0 and IP 192.168.100.1.

/etc/network/interfaces

auto eth0:0 iface eth0:0 inet static address 192.168.100.1 netmask 255.255.255.0

CentOS

With CentOS you have to create a new file for each IP you’d like to define under /etc/sysconfig/network-scripts directory. The file have to be named ifcfg-eth0:X where X is the alias number starting from 0 and eth0 is the actual network interface.

/etc/sysconfig/network-scripts/ifcfg-eth0:0

DEVICE=eth0:0 ONBOOT=yes BOOTPROTO=static IPADDR=192.168.100.1 NETMASK=255.255.255.0 TYPE=Ethernet

You can bring up all the additional IPs by calling:

/etc/sysconfig/network-scripts/ifup-aliases eth0


  1. Josh

    I have to add 16 totally different, non-sequential IP addresses. Doing it one by one is quite difficult. What should I do?

Comment

Enter your comment below. Fields marked * are required. You must preview your comment first before finally posting.





← Older Newer →