How to create VLAN in Ubuntu Linux

If you use Ubuntu Linux as a router, you may need to create VLAN (virtual LAN) interfaces in Ubuntu to divide your LAN. It is common in network infrastructures to use VLAN.

This post is intended to show you how to create VLAN  in Ubuntu Linux operating system. I am using Ubuntu 12.10 but it should be applicable for all Ubuntu versions. Simply follow the steps below:

Install the vlan package using apt-get tool

# apt-get install vlan
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 21 not upgraded.
Need to get 34.5 kB of archives.
After this operation, 163 kB of additional disk space will be used.
Get:1 quantal/main vlan amd64 1.9-3ubuntu8 [34.5 kB]
Fetched 34.5 kB in 2s (17.2 kB/s)
Selecting previously unselected package vlan.
(Reading database ... 53125 files and directories currently installed.)
Unpacking vlan (from .../vlan_1.9-3ubuntu8_amd64.deb) ...
Processing triggers for man-db ...
Setting up vlan (1.9-3ubuntu8) ...

Load the Vlan (802.1q) module

# modprobe 8021q
# echo 8021q >> /etc/modules

The second line command above to make vlan module load at boot time.

Add vlan interface by using ‘vconfig add [interface-name] [vlan_id]’ command syntax

# vconfig add eth0 100
Added VLAN with VID == 100 to IF -:eth0:-

A new interface eth0.100 should be created.
You are now ready to assign this new interface with an IP address using ‘ifconfig’ command as follows

# ifconfig eth0.100 netmask

To make the IP address assigned at boot, add the following lines to ‘/etc/network/interfaces’ file

auto eth0.100
iface eth0.100 inet static
vlan-raw-device eth0

Remove Vlan interface

In case you want to remove a vlan interface, use ‘vconfig rem [vlan-name]’ command syntax as follows:

# vconfig rem eth0.100
Removed VLAN -:eth0.100:-

I hope this post is helpful for those who are looking for tutorials on how to create VLAN in Ubuntu Linux.