How to Add an IP to a Linux Server

By | July 13, 2008

When you decide to rent a dedicated server, you almost in all cases get more than one IP address. This is used for DNS management and other stuff that is related to unique IPs. For example, you want to assign a dedicated IP to one of your site.

Let’s take we don’t have any panel installed (like CPanel, DirectAdmin, etc). How do we add an IP to server using command line only?

First of all, we need to login as root to perform IP addiction. Then we need to go to the folder with a configuration file:

cd /etc/sysconfig/network-scripts

I’d suggest you to backup your existing configuration if something goes wrong. Here is the command:

cp ifcfg-eth0 ifcfg-eth0_backup

Here I think that your main network interface is eth0, you should replace it with your interface name if it differs. We need to duplicate your working configuration file in order to create a new one for a new IP address we will add.

cp ifcfg-eth0 ifcfg-eth0:1

The command above copies your config file within the same directory. Now we need to open it with vi

vi ifcfg-eth0:1

Now we need to replace DEVICE=”eth0″ with DEVICE=”eth0:1″ and change IP address string IPADDR=”xxx.xxx.xxx.xxx” to the string with the IP you’re adding. You will probably need to assign this IP to your server on each boot. Then check the string below – it should look like ONBOOT=”yes”. Change this parameter to Yes if necessary. That’s all, let’s save the file by pressing ESC, then :wq, then Enter.

Let’s enable it by issuing the following command:

/sbin/ifup eth0:1

Now  if you type /sbin/ifconfig you should see your IP address under eth0:1 section.

Do service network restart. This will restart your network interfaces. You’re done. Your IP should be accessible at the moment,