Linux/Netzwerk/Konfiguration/vlan
vlan
- Howto use vlan (dot1q, 802.1q, trunk)
Manual config
modprobe 8021q apt install vlan vconfig add eth0 222 # 222 is vlan number ifconfig eth0.222 up ifconfig eth0.222 mtu 1496 #optional if your network card doesn't support MTU 1504B ifconfig eth0.222 10.10.10.1 netmask 255.255.255.0
Network init script config
Into /etc/modules add line:
8021q
In /etc/network/interfaces to section iface add parameter:
vlan-raw-device eth0
The interface name should be the raw interface name (the same as specified by vlan-raw-device), then a dot, then the VLAN ID, for example eth0.100. It can instead be "vlan" then the VLAN ID, for example vlan100. In either case, the VLAN ID is on the end, and this is the only place that it is configured.
Note: If you name your VLAN interfaces ethX.YYY, then there is no need to specify the vlan-raw-device, as the raw device can be retrieved from the interface name.
Eg:
auto eth0.222 iface eth0.222 inet static address 10.10.10.1/24 vlan-raw-device eth0
Bridges and VLANs
If you create VLAN interfaces only to put them into a bridge, there is no need to define the VLAN interfaces manually. Just config the bridge, and the VLAN interface will be created automatically when creating the bridge, e.g:
auto br1 iface br1 inet manual bridge_ports eth0.99 eth1.99 up /usr/sbin/brctl stp br1 on
Caveats when using bridging and vlan
#/etc/network/interfaces auto eth0 bri0 iface eth0 inet static address 192.168.1.1/24 iface eth0.110 inet manual vlan-raw-device eth0 iface bri0 inet static address 192.168.110.1/24 bridge_ports eth0.110 bridge_stp on bridge_maxwait 10
If you are using a brigded VLAN setup, which is probably useful for networking in virtualization environments, take care to only attach either a bridge device or VLAN devices to an underlying physical device - like shown above. Attaching the physical interface (eth0) to a bridge (eg. bri1) while using the same physical interface on apparently different VLANs will result in all packets to remain tagged. (Kernel newer than 2.6.37 and older than 3.2).