Use Vlan Tagging on your Linux Server

This tutorial was tested on a Ubuntu server, some commands and configuration files may vary.

To begin you need to install the following to be able to create and use Vlans on your Ethernet card:

sudo apt-get install vlan

Next, make sure that the dot1Q data encapsulation has been enabled in the kernel:

lsmod | grep 8021q –> ‘8021q’

If you don’t see  ‘8021q you need to enable it:

sudo modprobe 8021q

At this point, the module should be loaded, however, it won’t be enabled again after a reboot. To ensure that the module will always be loaded after reboots, you need to add it to the module loading list:

sudo sh -c ‘grep -q 8021q /etc/modules || echo 8021q >> /etc/modules’

Now you are able to add Vlans and configure them. You can create Vlans in the following way:

sudo vconfig add eth0 99

This will create Vlan99 and bind it with your eth0  Ethernet card.

To assign an address to it, you use the same commands to configure a network card except for 1 small detail:

sudo ifconfig eth0.99 netmask

Notice the fact that we added the  .99 to  our  ethernet card device:  ethO.99  to  assign the address to our Vlan instead of our ethernet card.

Your Vlan99 will be active when your ethernet card itself will be active, obviously.

However note that, just like the enabling of the 8021q module, your Vlan configuration isn’t permanent yet.

To make it permanent, you need to add the configuration to /etc/network/interfaces

sudo nano /etc/network/interfaces

auto eth0.99

iface eth0.99 inet static



vlan-raw-device eth0