Knowledge Base

Allows you to search a variety of questions and answers

Search

Search results

Centos/RedHat

To add the IPs in CentOs, RedHat or Fedora Core:

To add IPs in Linux, you need to create a new file for each IP in

1. # cd /etc/sysconfig/network-scripts/
directory. You will find this directory file with a name ifcfg-eth0 or something close to it.
2. # ls ifcfg-*
3. Open the following file in your favorite editor (I will use vi in this example):
# vi ifcfg-eth0
You will quickly notice your main IP address in that file. IMPORTANT: The layout of the file MUST be in this format.
4. To keep the same format, we will simply create a new file with the same content:
# cp ifcfg-eth0 ifcfg-eth0:1
You now have created the file ifcfg-eth0:1 which we will use for your second IP address. IMPORTANT: As with the contents of the file, the names of the file MUST follow that format (i.e. eth0:1, eth0:2, eth0:3, etc..).
5. Using your editor, open up the file we just created
# vi ifcfg-eth0:1
6. Edit the DEVICE line to be:
DEVICE=eth0:1
7. Edit the IPADDR line to the new IP:
IPADDR=*.*.*.* (put in the actual IP instead of the star symbols)
8. To make this IP usable on boot, make sure that the ONBOOT is set to yes:
ONBOOT=yes
9. Reapeat steps {iv} through {viii} for the other IP addresses you have.
10. When you have added all of the new IP addresses, you can issue one of the two following commands:
# service network restart
or
# /etc/rc.d/init.d/network -reload

If you have a whole range to add, there's a shortcut that can be done:

Create a file called ifcfg-eth0-range0 in the /etc/sysconfig/network-scripts directory. This file must contain the following strings:
 

Code:

ONBOOT=yes
IPADDR_START=FirstIP
IPADDR_END=LASTIP
CLONENUM_START=0
NETMASK=netmaskGOEShere
NO_ALIASROUTING=yes


Let's see what each of them does:

IPADDR_START: This is the first IP from the address range you want to bind to your ethernet device.
IPADDR_END: This is, of course, the last IP from that address range.
CLONENUM_START: This is the number that will be assigned to the first IP alias interface. For instance, if your Internet interface is eth0 and CLONENUM_START is 0, then this config file will create 100 interfaces starting with eth0:0 (eth0:0, eth0:1, eth0:2 etc) and ending with eth0:100, if you have 100 IPs to add. 

NOTE! Be careful if you need to add more ranges of IPs. You'll have to use a proper value for CLONENUM_START. For instance, if you need to add a second range with 100 IPs besides the one above, create a new file called ifcfg-eth0-range1 and set the CLONENUM_START to 101 so an overwrite will be avoided. Basically it's the number of ips already added to the box + 1.

After making any changes to any of the files created in the network-scripts directory, you have to run the following command so the changes are applied and the address range is activated:

# service network restart

 

See What Our Customers Say