How to setup a virtual IP in linux?

I remember I had setup some virtual IP and I had new interface named eth2:0 or eth2:1 but here I see eth2 is having 2 IP and I would like to know how it was setup?

root@localhost:~# ip addr show eth2
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 05:2b:21:2f:f2:65 brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth2
    inet scope global eth2
    inet6 fe20::27b:22ff:f1cf:7bc5/64 scope link
       valid_lft forever preferred_lft forever

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

andreasSystem AdminCommented:
This kind of assignment was made with the ip command

similar as that:

ip addr add dev eth0

as root or via sudo
Shiju JacobInfo Security ManagerCommented:
We need to create a ifcfg-eth1:1 file for the eth1:1 VIF. We use the existing ifcfg-eth1 or ifcfg-eth0  file as a template.

cd /etc/sysconfig/network-scripts

# cp ifcfg-eth1 ifcfg-eth1:1
# cat ifcfg-eth1:1

DEVICE=”eth1″  <—  change to  eth1:1
IPADDR= < — change to your new IP,
NAME=”System eth1″

Save the content to the file

service network restart
beer9Author Commented:
Andreas, How does additional IP works here after we have setup using the below command. Can it be any IP? or only the ip of subnet on which the other interface eth2/eth0 belongs to?

ip addr add dev eth0

Open in new window

andreasSystem AdminCommented:
can be any IP. using it myself to put a machine in several ip subnets to access some lab equipment
which are shippes with different pre configured ip addresses in different subnets.

with ip addr show you can list all assigned addresses.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.