User Tools

Site Tools


vlantaggingcentos

VLAN: Configuring VLAN-tagging on CentOS 7 with Tux

Hey, my name is "Tux"! Did you ever wonder how you can pass tagged VLANs to your CentOS system?

Hey, my name is "Tux" and this tutorial will show you how you can pass tagged VLAN traffic directly to your CentOS system so the CentOS system itself will tag/de-tag the network data packages instead of the according physical/virtual switch.



First thoughts

Basic informations

In CentOS, VLAN interfaces are based on existing network interfaces.
Example: Let's say you want to configure a VLAN interface with a VLAN-ID of 100. In addition let's say one of the existing standard network interface on your CentOS system is called eth0 on which its top you want to set the VLAN to. This would mean that your new VLAN interface would be called eth0.100, which would be based on the existing eth0 interface. In this case, the eth0 interface would be the parent network interface while the eth0.100 interface would be the child network interface.


Start of tutorial

First it is necessary to load the kernel module 8021q into the kernel:

$ modprobe --first-time 8021q

To make sure whether the module has been loaded into the kernel, please execute the previous command again, which should return a similiar error message to:
modprobe: ERROR: could not insert '8021q': Module already in kernel

Optional

For more informations about the kernel module please execute:

$ modinfo 8021q

Now execute…

$ ifconfig

…to find out the according parent network interface name you want to configure the VLAN interface on top of, which sould return something similiar to:
eth<myParentNetworkInterfaceNumber>
or
ens<myParentNetworkInterfaceNumber>.


Now inside the directory…
/etc/sysconfig/network-scripts
…open the according file called
ifcfg-<myParentNetworkInterface>:

$ vi ifcfg-<myParentNetworkInterface>

Comment out all content, except the following:

DEVICE=<myParentNetworkInterface>
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes


Save the file and quit the editor.
Now create a new file…

$ vi ifcfg-<myParentNetworkInterface>.<myVLANID>

(e.g. ifcfg-ens160.100)
…and add the following content:

DEVICE=<myParentNetworkInterface>.<myVLANID> (e.g. DEVICE=ens160.100)
BOOTPROTO=none
ONBOOT=yes
IPADDR=<myStaticAPAddress>
PREFIX=<mySubnetPrefix>
NETWORK=<myNetworkID>
GATEWAY=<myDefaultGatewayIPAddress>
VLAN=yes


Save the file and quit the editor.
Restart the network service:

$ systemctl restart network

Final note

It is also possible to configure multiple different VLAN child network interfaces on top of a single parent network interface!


End of tutorial

vlantaggingcentos.txt · Last modified: 2023/04/22