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 10.4.12.58/24 and 10.4.12.20/32. 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 10.4.12.58/24 brd 10.4.12.255 scope global eth2
    inet 10.4.12.20/32 scope global eth2
    inet6 fe20::27b:22ff:f1cf:7bc5/64 scope link
       valid_lft forever preferred_lft forever

Open in new window

beer9Asked:
Who is Participating?

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

x
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 10.4.12.58/24 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
BOOTPROTO=none
NM_CONTROLLED=”yes”
ONBOOT=yes
TYPE=”Ethernet”
UUID=”85b993bb-8e89-871b-887f-6d3973795928″
HWADDR=00:50:56:87:17:04
IPADDR=1.2.3.23 < — change to your new IP, 1.2.3.4
PREFIX=24
GATEWAY=1.2.3.1
DNS1=1.2.3.12
DOMAIN=myworld.ca
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
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 10.4.12.58/24 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
Linux

From novice to tech pro — start learning today.