Configuring VLANs in Ubuntu

Install the Vlan package:

sudo apt-get install vlan

Download the Vlan module (802.1q):

sudo modprobe 8021q

To automatically load the module when the system is started, we add to the /etc/modules file:

8021q

We edit the configuration file for the network interfaces /etc/network/interfaces eg the nano editor:

sudo nano /etc/network/interfaces

Add a VLAN interface to it:

auto eth0.5
iface eth0.5 inet static
address 192.168.5.1
netmask 255.255.255.0

We start the prescribed network interface:

sudo ifup eth0.5

Let’s look at the parameters:

sudo cat /proc/net/vlan/config

VLAN interface can be called differently, for example:
DEV_PLUS_VID_NO_PAD (eth0.5)
VLAN_PLUS_VID (vlan0005)
VLAN_PLUS_VID_NO_PAD (vlan5)
DEV_PLUS_VID (eth0.0005)

You can change the name type like this:

/sbin/vconfig set_name_type VLAN_PLUS_VID_NO_PAD

An example of adding a VLAN interface:

/sbin/vconfig add eth0 5
/sbin/ifconfig vlan5 up

If the VLAN interface is running as vlan5, then in /etc/network/interfaces we specify:

auto vlan5
iface vlan5 inet static
address 192.168.5.1
netmask 255.255.255.0
vlan_raw_device eth0

See also my articles:
Adding vlan to Ubuntu for ABillS
Configuring the Network in Linux

Leave a comment

Leave a Reply