How to create a sub-interface for tagged VLAN in CentOS

Assuming that the switch port connected to eth0 has untagged VLAN and tagged VLAN X and we want to create an interface for the tagged VLAN. The following explains the method for CentOS.

The interface name is eth0.X and we have to create a configuration file named ifcfg-eth0.X in /etc/sysconfig/network-scripts/ and the directives DEVICE=eth0.X and VLAN=yes in it. Here is an example:

DEVICE=eth0.X

BOOTPROTO=static

HWADDR=90:E2:BA:10:9C:0C

IPADDR=192.168.102.15

NETMASK=255.255.255.0

ONBOOT=yes

VLAN=yes

————————————————————————————————————-

In case of a live CD or PXE boot we don’t need to modify those files. The following commands always work but they won’t survive a reboot: (eth X and VLAN n)

# vconfig add ethX  n

# ifconfig ethX.n 1.2.3.4/24 up