Unlike windows, Linux is so flexible in networking. It has lots of built-in networking tools to customize, according to end user requirement. When look at the Linux virtual interfaces, they are useful for web servers, load balancing servers and proxy servers etc. Here I’m going guide how to configure virtual network interface in Centos ,but other Linux flavors process is similar.
1) Check available physical interfaces
1 2 3 4 5 6 7 8 9 |
[root@localhost]# ifconfig ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.2.11 netmask 255.255.255.0 broadcast 192.168.2.255 inet6 fe80::20c:29ff:fec0:4154 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c0:41:54 txqueuelen 1000 (Ethernet) RX packets 200866 bytes 170144300 (162.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 91148 bytes 9515819 (9.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
2) Create virtual interface
This example going to create virtual interface for Linux physical interface called “ens192”
vim /etc/sysconfig/network-scripts/ifcfg-ens192:0
1 2 3 4 5 6 7 |
DEVICE=ens192:0 IPADDR=192.168.4.10 NETMASK=255.255.255.0 GATEWAY=192.168.4.1 DNS=192.168.4.1 ONBOOT=yes BOOTPROTO=static |
if it is DHCP change boot protocol as below
1 |
BOOTPROTO=dhcp |
then save and exit
3) start virtual interface
1 |
ifup ens192:0 |
or
1 |
service network restart |
4) Verification
out put will shows newly created virtual interface, just like below
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[root@localhost]# ifconfig ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.2.11 netmask 255.255.255.0 broadcast 192.168.2.255 inet6 fe80::20c:29ff:fec0:4154 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:c0:41:54 txqueuelen 1000 (Ethernet) RX packets 201657 bytes 170199956 (162.3 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 91207 bytes 9524593 (9.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens192:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.4.10 netmask 255.255.255.0 broadcast 192.168.4.255 ether 00:0c:29:c0:41:54 txqueuelen 1000 (Ethernet) |