configure virtual network interface

0

On this article we will learn how to create a virtual network interface. But we need to know why we will do this. There are several reasons we may do this on a server.  Few of them are mentioned below.

  1. To assign more than one IP to a physical interface.
  2. By using single physical interface serve several services using different IPs.
  3. Using single physical interface with more than one IP for load balancing.
  4. Using more than one IP for round robin supporting application or services.

Now we start our work from here. This is actually a very simple process. We will start with our network interface configuration file which is /etc/sysconfig/network-scripts/ifcfg-enp0s3. So we have to open this file with an editor. For this we need to run the command below.

# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

Here we will see the below configuration.

HWADDR=00:0C:29:58:2C:95

TYPE=Ethernet

NAME=enp0s3

DEVICE=enp0s3

BOOTPROTO=dhcp

DEFROUTE=yes

PEERDNS=yes

PEERROUTES=yes

USERCTL=no

NM_CONTROLLED=yes

IPV4_FAILURE_FATAL=no

ONBOOT=no

IPADDR=192.168.1.64

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

DNS1=192.168.1.1

DNS2=8.8.8.8

Now exit from here. We need to check it just to ensure that our configuration is fine. Once you checked it. Let’s copy this file. For that we need to run the below command.

# cp /etc/sysconfig/network-scripts/ifcfg-enp0s3 /etc/sysconfig/network-scripts/ifcfg-enp0s3:0

Now we need to check it the file is created or not. For that run the below command.

#ls /etc/sysconfig/network-scripts/

Here we will get two file which are like ifcfg-enp0s3 and ifcfg-enp0s3:0. Once this is done let’s start the real work from here.

Here we will open the second file which is ifcfg-enp0s3:0, using vi/vim editor.

# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

We will find the previous configuration. We need to edit the following lines.

NAME=enp0s3

DEVICE=enp0s3

IPADDR=192.168.1.64

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

DNS1=192.168.1.1

DNS2=8.8.8.8

Now edit the above lines and put the following

NAME=enp0s3:0

DEVICE=enp0s3:0

IPADDR=172.16.1.90

NETMASK=255.255.255.0

GATEWAY=172.16.1.1

DNS1=172.16.1.1

DNS2=8.8.8.8

After we are done with the above work we are ready to start our network service and our virtual interface will be initialized with this.

#systemctl restart network

#ip addr

After running these two commands on terminal we will see that there are two interfaces working with two different IPs.

Now if we want we can add more interfaces with it. For that we have to follow the same process just need to change the device name, name of the interface and IP address with gateway and netmask.

Leave A Reply

Your email address will not be published.