Debian: add and configure VLAN

root's picture

In Debian, the proper way to configure vlans, after you install the vlan software, is to populate the configuration file /etc/network/interfaces. Of course, you can create them also with vconfig command. Examples after the debian way.

1. Install vlan software:

aptitude install vlan

Example:
root@eave:~# aptitude install vlan
The following NEW packages will be installed:
  vlan
0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 40.2 kB of archives. After unpacking 180 kB will be used.
Get: 1 http://ftp.us.debian.org/debian/ wheezy/main vlan amd64 1.9-3 [40.2 kB]
Fetched 40.2 kB in 3s (12.4 kB/s)
Selecting previously unselected package vlan.
(Reading database ... 44499 files and directories currently installed.)
Unpacking vlan (from .../archives/vlan_1.9-3_amd64.deb) ...
Processing triggers for man-db ...
Setting up vlan (1.9-3) ...

2. Add an interface definition for each VLAN to /etc/network/interfaces. You must use the vconfig naming convention in the form of ethx.y, where ethx is the physical interface name and y is the VLAN number.

In the example below, the interface on which we add vlan with ID 20, is iscsi1:
auto iscsi1.20
iface iscsi1.20 inet static
		address 192.168.72.1
		netmask 255.255.255.254
		mtu 9000

As mentioned at the beginning of this article, you can add vlans manually too but they will be lost after reboot if you do not add the command to /etc/rc.local or populate /etc/network/interfaces like in the above example.

How to add VLAN with vconfig:

vconfig add ethX X

Example:
root@eave:~# vconfig add iscsi1 99
Added VLAN with VID == 99 to IF -:iscsi1:-
root@eave:~# ifconfig iscsi1.99
iscsi1.99 Link encap:Ethernet  HWaddr 08:00:27:09:76:28
          BROADCAST MULTICAST  MTU:9000  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Is it possible to add vlan via ip command (provided by the 8021q kernel module):

ip link add link ethX name ethX.X type vlan id X

Example:
root@core:~# ip link add link iscsi name iscsi.40 type vlan id 40
root@core:~# ifconfig iscsi.40
iscsi.40  Link encap:Ethernet  HWaddr 56:13:0e:96:35:d7
          BROADCAST MULTICAST  MTU:9000  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

How to remove VLAN via vconfig command:

vconfig rem ethX.X

Example:
root@eave:~# vconfig rem iscsi1.99
Removed VLAN -:iscsi1.99:-
root@eave:~# ifconfig iscsi1.99
iscsi1.99: error fetching interface information: Device not found

Or remove with ip command:

ip link delete ethX.X

Example:
root@core:~# ip link delete iscsi.40
root@core:~# ifconfig iscsi.40
iscsi.40: error fetching interface information: Device not found

Errors:

1. RTNETLINK answers: Numerical result out of range

This happens if you try to modify the vlan mtu with a value higher than the one on real interface. For example, if you want to add mtu 9000 to the vlan inteface, you will have to modify mtu to 9000 on the real interface first (initial value of mtu is 1500).

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content

root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root
root