Monday, January 11, 2010

Setting virtual ip in centos

Virtual ip is an ip that bind to a physical ethernet card that already have physical ip address. To set virtual ip in centos, follow the below steps:

1. We will add virtual ip to eth0. Below is original configuration of /etc/sysconfig/network-scripts/ifcfg-eth0. ifcfg-eth0 is the original configuration file for eth0.
# vi /etc/sysconfig/network-scripts/ifcfg-eth0

BOOTPROTO=static
BROADCAST=192.168.0.255
HWADDR=00:0C:29:C8:AA:7C
IPADDR=192.168.0.10
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes
TYPE=Ethernet

2. Create new virtual configuration file by copying and editing(change IPADDR and remove HWADDR) the ifcfg-eth0 configuration file

# cd /etc/sysconfig/network-scripts
# cp ifcfg-eth0 ifcfg-eth0:0
# vi ifcfg-eth0:0

BOOTPROTO=static
BROADCAST=192.168.0.255
IPADDR=192.168.0.11
NETMASK=255.255.255.0
NETWORK=192.168.0.0
ONBOOT=yes
TYPE=Ethernet


3. Restart network
# /etc/init.d/network restart

4. Check your new virtual ip using ifconfig
# ifconfig

4 comments:

Anonymous said...

thanks for your article.

wellnux.
http://blog.shareyourmenu.com

Anonymous said...

"ONBOOT=yes" should more correctly be as follows across the eth0 and eth0:0 pairs,

/etc/sysconfig/network-scripts/

ifcfg-eth0
ONBOOT=yes

ifcfg-eth0:0
ONPARENT=yes

Anonymous said...

So basically you need minimal?
BOOTPROTO=static
IPADDR=192.168.0.11
NETMASK=255.255.255.0
TYPE=Ethernet
ONBOOT=yes
So apparently ONPARENT is also advised instead of ONBOOT?
I myself kept the option DEVICE=eth0:x in place.

Anonymous said...

how about if I set virtual ip is different ip address segment with default(physical). Is it possible? and how?