You may have a Centos dedicated server or VPS, and you’ve been assigned additional IP addresses, which have not been configured by your hosting provider. There are good reasons your host won’t have configured these for you, because if you are using virtualization, many VPS control panels need to manage these IPs, and so it should be left unconfigured in your OS. That said, if you are using a normal OS, or need to configure IPs inside a VPS, then obviously this leaves you with a bit of work to do.
Configuring additional IP addresses (also known as virtual interfaces) on Centos servers is not terribly difficult, but you do need to know a few things about it to make it work. This guide will help you get these configured, so that in the future you’ll know how to do this yourself without relying on your host to do it for you.
Without further ado, here are the instructions:
How to configure addon IP addresses on Centos servers
The first thing you need to know is what interface is the active one on your server. Typically this would be “eth0” but this is not always the case. So first of all, run the following command:
This will output some results, and you will be looking for the portion that matches your server’s primary IP address. Here is an example output from one of our servers:
eth0 Link encap:Ethernet HWaddr 00:16:3E:1A:A6:DD
inet addr:18.104.22.168 Bcast:22.214.171.124 Mask:255.255.255.248
eth0:0 Link encap:Ethernet HWaddr 00:16:3E:1A:A6:DD
eth0:1 Link encap:Ethernet HWaddr 00:16:3E:1A:A6:DD
In this case, 126.96.36.199 is the IP address associated with the primary interface on the server. Unimportant information was left out with the placeholder “…”. As you can see, this IP is configured on eth0, so eth0 is the interface we need to configure additional IPs on.
Next, from the above output, you may already see additional IPs configured on eth0, listed as eth0:0, eth0:1, etc. Make a note of the highest numbered interface here, as your additional IPs need to be configured with a number 1 higher than that. If there are no “eth0:X” interfaces, your first one can start with “0”. These are called “clone numbers”, and you need to make a note of the first available clone number, either “0” (if none exist already), or a number one higher than the highest numbered one that already exists. In our example, the highest clone number currently in use is “1”, so we must start any additional IPs with clone number 2 or higher.
Next we need to see if you have any “range files” already configured. Run the following command and note the output:
In our example, we see the following:
-rw-r–r– 1 root root 108 Jul 10 2012 /etc/sysconfig/network-scripts/ifcfg-eth0
-rw-r–r– 1 root root 108 Jul 10 2012 /etc/sysconfig/network-scripts/ifcfg-eth0-range0
-rw-r–r– 1 root root 102 Mar 31 2011 /etc/sysconfig/network-scripts/ifcfg-eth1
-rw-r–r– 1 root root 254 Mar 19 2014 /etc/sysconfig/network-scripts/ifcfg-lo
Note that we already have a “range0” file, so our next file will need to be one higher, i.e. “ifcfg-eth0-range1”
Now that we know what “range file” we need to create (in our example, ifcfg-eth0-range1) and what clone number we need to start with (in our example, eth0:2, so clone number 2), we can create the new file:
The minimum amount of information needed in this range file is as follows:
Enter the first usable IP address in your range under the IPADDR_START= line and the last usable IP after IPADDR_END= on the next line.
The netmask is also known as the network mask or subnet mask, and should have been provided for you by your hosting provider. Generally this would be in the format 255.255.255.X where X is a number between 0 and 252, depending upon the size of the subnet you’ve been assigned.
Finally, you need to enter the next available clone number on the last line as we discussed previously.
In the example we’re working with on our server, a completed and correct configuration might be:
The exact values above will vary depending upon what IP addresses you’ve been assigned by your host, and how many addon IPs are already configured on your server.
After creating the range file appropriately, you’ll need to activate the new IPs, which you can do in Centos with the following command:
service network restart
After a few seconds, the server should have the network restarted, including your new IP addresses. You can confirm that the new IPs have been correctly activated on your server by running the following command:
The output of the above should now show appropriate eth0:X entries for the entire range of IPs you’ve configured in your “range file”. If they do not show up here, there may have been an error in your configuration that needs to be corrected.
If the IPs do show up in ifconfig, they will be available for use right away. That said, if you want a program such as apache to listen on the new IPs, you may need to restart that program. In some cases, it may be easier just to reboot the server rather than restart individual programs to use the new IPs, particularly if the server is not currently being used in production.
So that’s it! You’ve learned how to configure ranges of additional IP addresses in Centos as “virtual interfaces”. Although some of the details may look tricky, after you’ve done it a couple of times, you’ll see that it’s actually pretty simple.
In a future article we’ll discuss how to configure addon IPs in Ubuntu and Debian, although unfortunately in those OS’s there is no idea of an “IP range”, and so each IP would have to be configured individually, which can take a lot of time.
If you have any questions about this information, or want to learn about IOFlood.com Centos Dedicated Servers, email us at sales [at] ioflood.com