How to Configure VLAN in Ubuntu

Don’t know how to configure VLAN in ubuntu???…Well there are different ways to set VLAN in Ubuntu, we are going with the simplest one we think.

In VoIP telephony, sometimes configuring VLAN becomes essential. In this article we are trying to suggest you the simplest method to configure it.

To use VLAN you should first install it on your system. In Ubuntu, use the following command to install VLAN:

sudo apt-get install vlan

Now make sure that the Linux kernel driver (module) called 8021q is loaded:

lsmod | grep 8021q

If the module is not loaded, load it with the following modprobe command:

sudo modprobe 8021q

Create a new interface that is a member of a specific VLAN, we are taking VLAN id “300” and ethernet interface “eth1” in this example.

To add VLAN ID, use vconfig add command for eth1 interface:

sudo vconfig add eth1 300

The vconfig add command creates a vlan-device on eth1 which result into eth1.300 interface. You can use normal ifconfig command to check device information:

ifconfig eth1.300

Now assign IP address (we are taking 192.168.1.100 in this example, you can take yours) to vlan interface using ifconfig command:

ifconfig eth1.300 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 up

To get detailed information about your recently added VLAN interface, type:

cat /proc/net/vlan/eth1.300

In between, If you wish to delete VLAN interface, you can use vconfig rem command as follows:

ifconfig eth1.300 down
sudo vconfig rem eth1.300

Make VLAN configuration permanent

You learned to set VLAN id on particular ethernet interface, but this will reset when you reboot the system. To make these VLAN configuration permanent on a system edit the /etc/network/interfaces file.

Open the /etc/network/interfaces file by any of your preferable editor, we are using gedit.

sudo gedit /etc/network/interfaces

And update the configuration in the file as:

## vlan for eth1 with ID – 300 on a Debian/Ubuntu Linux##
auto eth1.300
iface eth1.300 inet static
address 192.168.1.100
netmask 255.255.255.0
vlan-raw-device eth1

Save and close the file, you have successfully set and configured VLAN on your desired Ethernet interface.