Add IP Aliases in RH or CentOS

Linux specific questions/information are gathered here. The main thrust of topics are applied to Centos/RedHat(RH)/Debian/Ubuntu/Gentoo distributives

Add IP Aliases in RH or CentOS

Postby lik » Fri Aug 06, 2010 6:27 am

If you want to add additional IPs to the same NIC you should do the following:

1. Adding a network alias from command line in RH or CentOS Linux:
Code: Select all
/sbin/ifconfig lo 127.0.0.1
/sbin/ifconfig eth0 up
/sbin/ifconfig eth0 10.0.0.1
/sbin/ifconfig eth0:1 192.168.0.1
/sbin/ifconfig eth0:2 192.168.0.2


2. Configure a script to setup your network/IP aliases on boot:
Code: Select all
cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-eth0:1
cp ifcfg-eth0 ifcfg-eth0:2

Then edit ifcfg-eth0:1 and ifcfg-eth0:2 files and add your IP aliases there. For example:
cat /etc/sysconfig/network-scripts/ifcfg-eth0\:1
Code: Select all
DEVICE=eth0:1
IPADDR=192.168.0.2
NETMASK=255.255.255.248
ONBOOT=yes

3. Also in RH and CentOS Linux it is possible to add as IP aliases a range of IPs. To do that go to :
Code: Select all
cd /etc/sysconfig/network-scripts/

directory and create a file:
Code: Select all
touch ifcfg-eth0-range0

with the following content:
Code: Select all
IPADDR_START=192.168.0.1
IPADDR_END=192.168.0.6
CLONENUM_START=1
NETMASK=255.255.255.248

* IPADDR_START is the address, from which your IP range is starting.
* IPADDR_END is the address, by which your IP range is ending.
* CLONENUM_START is the number of virtual device the first IP address will be assigned to. In the above example, applying configuration changes will make IP address 192.168.0.1 to be mapped to eth0:1 virtual device. 192.168.0.2 to eth0:2 etc.
You can create several ranges (ifcfg-eth0-range1, ifcfg-eth0-range2 etc.). Just take care of CLONENUM_START value for these ranges not to overlap. To apply configuration you will need to issue:
Code: Select all
service network restart
lik
Founder
Founder
 
Posts: 497
Joined: Wed Dec 15, 2010 3:21 am

Return to Linux specific

 


  • Related topics
    Replies
    Views
    Last post