setup a virtual ethernet device on linux

May 2, 2011 by: Akhthar Parvez

What would you do if you want to add one more IP to your system. Attach one more network device? No! Then what? You would setup a virtual ethernet device.

Suppose you have a physical eth device named eth0 as below:

eth0 Link encap:Ethernet HWaddr 00:1C:C0:78:31:E0
inet addr:192.168.1.20 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3899483 errors:0 dropped:0 overruns:0 frame:0
TX packets:5332505 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1648569488 (1.5 GiB) TX bytes:1417767181 (1.3 GiB)
Interrupt:50 Base address:0x8000

And now you want to add another IP address (192.168.1.21) to the system. That’s so easy!

First copy the file /etc/sysconfig/network-scripts/ifcfg-eth0 to /etc/sysconfig/network-scripts/ifcfg-eth0:1
and then edit the following lines:
DEVICE=eth0:1
IPADDR=192.168.1.21

So the whole file /etc/sysconfig/network-scripts/ifcfg-eth0:1 would look like this:
# Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller
DEVICE=eth0:1
BOOTPROTO=none
BROADCAST=192.168.1.255
HWADDR=00:1c:c0:78:31:e0
IPADDR=192.168.1.21
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes

Restart the network service

/etc/init.d/network restart

Run ifconfig now and you should see the new virtual device eth0:1 there. 🙂

Filed under: Linux,Networking
Tags: , , ,

Leave a Reply

You must be logged in to post a comment.