Adding an IP Address to an Interface With Red Hat and CentOS

Last Updated: October 3rd, 2016 - Paul Anderson

There is some apparent voodoo on what, exactly, is needed to add an IP address to an interface using Red Hat style scripts. We have tested this on Red Hat Enterprise 3 and CentOS 4, and it appears that the convention is quite forgiving. This makes sense, really, since if you hose up these interfaces, well, you can’t administer the machine remotely. Let’s look at our current interfaces on eth0:

Now, the hardware address will vary, certainly, and other entries may or may not be on your system. There is a lot of variation here. The safest way is to copy the config file for the interface you want to add the IP address to, and then edit that file. It really doesn’t matter what you call the file. We will standardize on ifcfg-eth0:1 later in the article, and believe this is a good naming scheme; however, we can also call it ifcfg-eth0-blahsecond:

The colon after eth0 on the interface name does seem to be required with this CentOS 4 box. Without it, the startup script seems to hang. Also, notice how the stuff after the : is truncated to 4 characters. Let’s change the device name to something more standard:

That looks more standard, and will avoid possible problems in the future because this is how everybody does it for the most part. Notice how it is not true that the file name has to match the interface name? Let’s make it match, though:

Now we have the typical config, it works fine, and most anybody will know what you are doing and how. In summary, to add an IP, find the highest device number on the interface using ifconfig, and add another IP using that device name in a file named in the same way. Fairly easy. Do make a copy of anything you change, of course, and do be very careful you don’t make the machine unavailable over the network. If at all possible, do this from a console or serial terminal.