Configuring virtual network interfaces in Linux
Introduction
For the Debian based system
Did you know that you can assign more that one IP address to a single physical network interface? This technique is quite useful, for example when working with Apache and virtual hosts, as it allows you to access same Apache server by using two different IP addresses.
Temporary virtual network interface
ifconfig
check network interface name and then add
Replace enp2s0 as per your network interface name
sudo ifconfig enp2s0:0 219.91.251.164
Making the Interface permanent
These interfaces are temporary that means it will not last after reboot so to make it persistent we need to add it insudo vi /etc/network/interfaces
iface eth0:0 inet static
address 219.91.251.164
netmask 255.0.0.0
broadcast 123.255.255.255
For redhat based system
From the above output we can see that currently we have configured eth0 network interface only. Next, we are going to locate a corresponding network interface configuration file for eth0:
# grep -l DEVICE.*eth0 /etc/sysconfig/network-scripts/*
The configuration file responsible for the
eth0
network interface is /etc/sysconfig/network-scripts/ifcfg-eth0
[root@rhel7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" NETBOOT="yes" HWADDR="08:00:27:15:38:B7" TYPE="Ethernet" BOOTPROTO="none" NAME="eth0" UUID="462f4834-4fe7-43a7-84e7-83b2722e94c1" ONBOOT="yes" IPADDR="10.1.1.110" NETMASK="255.0.0.0" GATEWAY="10.1.1.1"In order to create a virtual network interface we can first copy a master configuration file
/etc/sysconfig/network-scripts/ifcfg-eth0
and then edit its content to set an appropriate network interface name and IP address:[root@rhel7 ~]# cd /etc/sysconfig/network-scripts/ [root@rhel7 ~]# cp ifcfg-eth0 ifcfg-eth0:0 [root@rhel7 ~]# cp ifcfg-eth0 ifcfg-eth0:1Next, we need to edit
DEVICE, NAME, IPADDR
in both virtual network configuration files. Below you can see both edited configuration files:on Sysvinit
2. Bringing interfaces up/down
Two methods can be used to bring interfaces up or down.
Usage:
# ip link set dev <interface> up # ip link set dev <interface> downExample:
# ip link set dev eth0 up # ip link set dev eth0 down
Comments
Post a Comment