How to configure 802.1q VLAN tagging on RHEL / CentOS 7/8 and Fedora interfaces

VLAN tagging is a method for handling multiple VLANs on a network port. The VLAN tag is used to tell which packet belongs to which VLAN, because the packet traverses the network medium. In this guide, we will configure 802.1q VLAN tagging in the network interfaces of RHEL / CentOS and Fedora systems.

To create a VLAN, you need to create an interface on top of another interface called a “ parent interface. ” The VLAN interface will use the VLAN ID to mark packets when passing through the interface, and the returned packets will be untagged.

Before performing any configuration, make sure that the 8021q module is loaded.

sudo modprobe --first-time 8021q
modinfo 8021q

In this example, I will configure one enp6s0 Interface on the server.

$ ip link  show  dev enp6s0
2: enp6s0:  mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 38:90:a5:14:96:54 brd ff:ff:ff:ff:ff:ff

You can use the Network Manager command line tool – Antarctica Do this or edit the network configuration file directly.

Edit the configuration file manually

Edit the parent interface configuration file and make the following settings.

$ sudo vim /etc/sysconfig/network-scripts/ifcfg-enp6s0
TYPE=Ethernet
NAME=enp6s0
DEVICE=enp6s0
BOOTPROTO=none
ONBOOT=yes

As shown above, we have set the interface to start at startup, we do not assign IP information here.

Now configure the VLAN interface. The configuration file name should add a parent interface . Character plus VLAN ID number. In my setup, the VLAN ID is twenty oneAnd the parent interface is enp6s0, so the configuration file name should be:

sudo vim /etc/sysconfig/network-scripts/ifcfg-enp6s0.21

All network configuration information is added to the file.

DEVICE=enp6s0.21
BOOTPROTO=none
ONBOOT=yes
IPADDR=172.10.10.11
GATEWAY=172.10.10.1
DNS1=172.10.10.1
DNS2=8.8.8.8
PREFIX=24
VLAN=yes

After making changes, restart the network services for the changes to take effect.

sudo systemctl restart network

Alternatively, call up the interface manually.

sudo ifdown enp6s0 && sudo ifup enp6s0
sudo ifup enp6s0.21

Confirm the IP address of the interface.

$ ip ad | grep enp6s0
2: enp6s0:  mtu 1500 qdisc mq state UP group default qlen 1000
49: [email protected]:  mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 172.10.10.11/24 brd 172.10.10.255 scope global noprefixroute enp6s0.21

Using NMCLI tools

The same configuration can be done from the command line interface. For this method, the NetworkManager service should be running.

$ systemctl status NetworkManager

Check the current network configuration.

$ nmcli con show

Create an 802.1Q VLAN interface on the Ethernet interface enp6s0With VLAN interface VLAN21 And ID twenty one, Issue the following command:

$ nmcli con add type vlan con-name VLAN21 ifname VLAN21 dev enp6s0 id 21

You can then assign an IP address to the VLAN interface.

nmcli connection modify VLAN21 ipv4.addresses 172.10.10.11/24 
ipv4.method manual ipv4.gateway 172.10.10.1 
ipv4.dns 172.10.10.1 +ipv4.dns 8.8.8.8

To view all the parameters related to the VLAN created above, issue the following command.

$ nmcli connection show VLAN21

You have successfully configured VLAN tagging on an interface in your RHEL / CentOS or Fedora server.

Similar articles:

Add secondary IP address to CentOS / RHEL network interface

Ifconfig vs ip usage guide on Linux

Create Openstack network and subnet

Sidebar