How To Configure or Tag VLAN In Linux

Learn the step-by-step guide of how to configure VLAN in Linux.

You may click here to learn about the basic knowledge of networking in Linux

In summary, VLAN (Virtual Local Area Network) is just a way of breaking larger networks into smaller ones. With the use of VLANs, your network can be segmented.

click here to understand the basics of VLAN in Linux.

In RHEL, the VLAN module/driver is 8021q, the module has to be loaded before one can tag a VLAN.

If the module is not loaded, use the command below to load the module.

# modprobe 8021q

VLAN ID can be tagged on a physical interface or on a bond or teamed interface.


How To Configure or Tag VLAN In Linux Using CLI – RHEL 7 & RHEL 8

1. Tag the VLAN ID on any of the interfaces you wish to configure the VLAN on.

In this case, the VLAN will be tagged on the physical NIC, ens33.

[root@localhost ~]# vim /etc/sysconfig/ifcfg-ens33
DEVICE=ens33
NAME=ens33
ONBOOT=yes

2. Create the VLAN interface and tag the VLAN ID to the interface.

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33.121
DEVICE=ens33.121
NAME=ens33.121
DEFROUTE=yes
BOOTPROTO=none
IPADDR=10.24.121.22
NETMASK=255.255.255.0
GATEWAY=10.24.121.1
DNS1=10.24.121.2
NETWORK=10.24.121.0
VLAN=yes
ONPARENT=yes

3a. On RHEL 7, restart NetworkManager and network.

[root@localhost ~]# systemctl restart NetworkManager
[root@localhost ~]# systemctl restart network

3b. On RHEL 8, restart NetworkManager.

[root@localhost ~]# systemctl restart NetworkManager

3c. You may want to restart all the interfaces associated with VLAN.

[root@localhost ~]# nmcli conn down ens33 && nmcli conn up ens33
[root@localhost ~]# nmcli conn down ens33.121. && nmcli conn up ens33.121

4. Verify your configuration.

[root@localhost ~]# ip route

default via 10.24.121.1 dev ens33.121 proto static metric 400 
10.24.121.0/24 dev ens33.121 proto kernel scope link src 10.24.121.22 metric 400 
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown 

How To Tag VLAN ID In Linux Using nmtui – RHEL 7 & RHEL 8

1. Edit the interface configuration file you want to tag the ID on as below.

The same goes with a bond or teamed interface.

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
DEVICE=ens33
NAME=ens33
ONBOOT=yes

2. Initialize nmtui.

[root@localhost ~]# nmtui

*Choose the interface you want to tag the VLAN ID on

*Choose the type of connection, in this case VLAN.

vlan in Linux

*Input the necessary network properties as it is below.

*Navigate to ok and quit.

3a. On RHEL 7, restart NetworkManager and network.

[root@localhost ~]# systemctl restart NetworkManager
[root@localhost ~]# systemctl restart network

3b. On RHEL 8, restart NetworkManager.

[root@localhost ~]# systemctl restart NetworkManager

3c. You may want to restart all the interfaces associated with VLAN.

[root@localhost ~]# nmcli conn down ens33 && nmcli conn up ens33
[root@localhost ~]# nmcli conn down ens33.121. && nmcli conn up ens33.121

4. Verify your configuration.


How To Configure or Tag VLAN over a Bond or Teamed Interface In RHEL 7 & RHEL 8 Using Network Scripts/CLI

1. On the bond interface or teamed interface, edit the configuration file as below.

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond1
DEVICE=bond1
NAME=bond1
ONBOOT=yes
BONDING_OPTS="mode=0 miimon=100"

2. Create the VLAN interface, and tag the vlan to the bond or teamed interface.

In this case, the VLAN ID is 121.

NOTE: if you want to create more than one VLAN, keep tagging the VLAN IDs on the interface.

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond1.121
DEVICE=bond1.121
NAME=bond1.121
DEFROUTE=yes
BOOTPROTO=none
IPADDR=10.24.121.22
NETMASK=255.255.255.0
GATEWAY=10.24.121.1
DNS1=10.24.121.2
NETWORK=10.24.121.0
VLAN=yes
ONPARENT=yes

3a. On RHEL 7, restart NetworkManager and network.

[root@localhost ~]# systemctl restart NetworkManager
[root@localhost ~]# systemctl restart network

3b. On RHEL 8, restart NetworkManager.

[root@localhost ~]# systemctl restart NetworkManager

3c. You may want to restart all the interfaces associated with VLAN.

[root@localhost ~]# nmcli conn down bond1 && nmcli conn up bond1
[root@localhost ~]# nmcli conn down bond1.121. && nmcli conn up bond1.121

4. Verify your configuration

[root@localhost ~]# ip a

.......
22: bond1.121@bond1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:ae:ba:86 brd ff:ff:ff:ff:ff:ff
    inet 10.24.121.22/24 brd 10.24.121.255 scope global noprefixroute ens33.121
...........

Tutorial Video On How To Configure VLAN In Linux on a Bond or Teamed Interface

Your feedback is welcomed. If you love others, you will share with others.

Be the first to comment

Leave a Reply

Your email address will not be published.


*