Wallpapers Forums Login

How To Add Virtual Ip Address To Linux

on this post i will teach you how you can add an additional ip interface address to your linux server. we will be adding ip 10.0.0.2

lets say we already have binded our ip of 10.0.0.1 in our NIC which is ETH0 on this step by step tutorial guide i will show you how you can add anothre ip address to the same interface but it will be a virtual interface. this will be very easy using ssh. so login to your server with root acess or as a super user.

NOTE: i am using a red hat fedora core system for this example, i think is should work on centos but not sure about other distributions like ubuntu or debian

the first command is going to make a copy of the current interface:
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0


now that we have a copy of our new virtual interface, you need to edit the file:
nano /etc/sysconfig/network-scripts/ifcfg-eth0:0
NOTE: i am using nano as my text editor, im sure you can use whatever your favorite text editor is. like VI for example

ok, when you first open ifcfg-eth0:0 it will probably look like this:

NETMASK=255.255.255.0
DEVICE=eth0
ONBOOT=yes
TYPE=Ethernet
ETHTOOL_OPTS="duplex full speed 100 autoneg off wol g"

IPADDR=10.0.0.01


now, change the following lines/fields to match the new virtual ip:

DEVICE=eth0:0
IPADDR=10.0.0.02


On my sample here, i only change DEVICE and IPADDR

now that our new virtual interface it configured, its time to make the changes work, how do we do that.. we do that by restarting our network. so send this unix shell command to restart our network in our server

service network restart


or another way to restart your network is with this command:
/etc/init.d/network restart


ok, if you are going through ssh, wait like 10 seconds the if the changes took affect and there were no problems, it should work ok. if you get disconnected, try to connect to your ssh session again.

now that the network has been restarted, you can test it by pinging your new virtual ip
ping 10.0.0.2


after you ping you should get successful ping like this:
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=0.018 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.018 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.021 ms
64 bytes from 10.0.0.2: icmp_seq=4 ttl=64 time=0.019 ms


thats it,

Maik Wed Jan 25, 2012
This is NOT a virtual IP address (read: one address shared by two hosts) it's a virtual NIC...
Ken Tue Dec 20, 2011
As mentioned above, if you add an IP or gateway at the command line like:

ifconfig -a eth0:1 <ip address>

route add default gateway <ip addres> eth1

it will not survive a reboot, you need to configure it in the cfg files mentioned or 'network' file for the gateway to survive a reboot.


Also "virtual IP" sounds funny but is technically correct although it sounds funny. It is a VIP (virtual IP) off an existing interface.

Denish Tue Aug 23, 2011
You have created virtual interface not the virtual IP .The heading is not correct.Please correct it
Allan Mon May 30, 2011
Verry good ... thanks friend...
Morlack Thu May 26, 2011
- at - saravana : I suppose ifconfig -a has temporary effect (like ifconfig eth0 down, when u restart network eth0 will be up again). If you want a permanent config u must modify the network-scripts files.
saravana Tue Mar 01, 2011
hi
but how i can do by giving comments?
just like
ifconfig -a eth0:1 <ip address>
..i used this..but when i restrat the services .virtual ip could disappear,,
how i can resolve
nillgun Tue Jul 20, 2010
wow (;
thank man,
I do complite.................
rony Thu Mar 25, 2010
You can add virtual ip in debian derivative by like this :
#vi /etc/network/interfaces

eth0
iface eth0 inet static
address 192.168.0.5
netmask 255.255.255.0
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x

auto eth0:1
iface eth0:1 inet static
address 192.168.0.50
netmask 255.255.255.0
network x.x.x.x
broadcast x.x.x.x
gateway x.x.x.x
Raja Wed Feb 10, 2010
**************Thanking you*************


anrudh65 Wed Jul 15, 2009
15-6967-04.jpg
i chk this post. i searched for this linux ip address details.but it is better if it is in a detailed information. i normally use the website to chk the ip address from ip-details /
harsh Wed Jul 15, 2009
you chk the details from whatismyipaddress /
Manjunath Tue Jan 20, 2009
thanks, my problem of virtual ip is solved................

Related Content

Information

Share

wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon May 06, 2013 (-8 GMT)
Powered by: Webune Forums V5