Adding Virtual nic's to *nix
Sometimes, we need to add virtual NICs to our *nix machine. To do this, copy the eth0 configuration file from /etc/sysconfig/network-scripts/
:
[root@test ~]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1
Edit the ifcfg-eth0:1
file and remove the "HWADDR" line:
[root@test ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0:1
After editing, the file should look like this:
DEVICE=eth0:1
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.56.102
GATEWAY=192.168.56.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
You can then use the ifup
command to bring the virtual NIC up:
[root@test ~]# ifup eth0:1
In Debian and other Debian-based distributions:
Open the interfaces configuration file:
root@debian:~# vim /etc/network/interfaces
The file will look like this:
auto eth0
iface eth0 inet static
address 192.168.56.101
netmask 255.255.255.0
Add the following lines to include a virtual NIC:
auto eth0:1
iface eth0:1 inet static
address 192.168.56.102
netmask 255.255.255.0
Now, you can use the ifup
command to activate the virtual NIC:
root@debian:~# ifup eth0:1
Comments
Post a Comment