VLAN Configuration in Redhat Linux

Usually it is not required to configure the Vlan in a client system and the configuration is done on the switch port.
But some times you may need to tag the packets with the Vlan ID.

In Redhat Linux and its variants use the sub-interface to add the Vlan tagging functionality.

1. Make sure the 801.1q module is already loaded

lsmod | grep 8021q

2. If module is not loaded load it using modprob command

modprobe 8021q

3. Configure your physical interface in /etc/sysconfig/network-scripts/ifcfg-ethX, where X is your interface number.

DEVICE=ethX
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes

4. Configure the sub-interface for the VLAN. If the Vlan ID is 100 the subinterface should be ethX.100

/etc/sysconfig/network-scripts/ifcfg-ethX.100

DEVICE=ethX.100
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.2.100.10
NETMASK=255.255.255.0
USERCTL=no
NETWORK=10.2.100.0
VLAN=yes

5. Restart the network service

service network restart

6. Check the VLAN status in /proc

cat /proc/net/vlan/ethX.100

It is possible to configure multiple vlan interfaces on a single physical interface.

You can also use the vconfig command for configuring VLAN interfaces

# vconfig add eth0 100
# ifconfig eth0.100
# ifconfig eth0.100 10.2.100.10 netmask 255.255.255.0 broadcast 10.2.100.255 up
# cat /proc/net/vlan/eth0.100
# ifconfig eth0.5 down
# vconfig rem eth0.100