Back to the main page

Using VLAN in Debian (and its clones)

One of projects many face can be IP change and here is example of setting a Linux box that's on more then one VLAN, so if you lose connection while changing IP of a device, you can easily access that device over different VLAN. Note here that VLAN ID stays same but subnet is changing and there are 2 VLANs in this example. And Linux box is Linux Mint.

# cat /etc/os-release
NAME="Ubuntu"
VERSION="12.04.5 LTS, Precise Pangolin"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu precise (12.04.5 LTS)"
VERSION_ID="12.04"

First, make sure 'vlan' package is installed.
# apt-get install vlan

Make sure module 8021q is loaded after system reboots.
# cat /etc/modules | grep 8021q
8021q

# modinfo 8021q
filename:       /lib/modules/3.2.0-32-generic/kernel/net/8021q/8021q.ko
version:        1.8
license:        GPL
alias:          rtnl-link-vlan
srcversion:     367A727F863FF42633B5097
depends:        garp
intree:         Y
vermagic:       3.2.0-32-generic SMP mod_unload modversions 686

The interface configuration is:
# cat /etc/network/interfaces
auto lo
iface lo inet loopback

# vlan322
auto eth0
allow-hotplug eth0
iface eth0 inet static
    address 10.aa.bb.136
    netmask 255.255.252.0
    broadcast 10.aa.bb.255
    gateway 10.aa.bb.1

auto eth0:0
allow-hotplug eth0:0
iface eth0:0 inet static
    address 144.aa.bb.136
    netmask 255.255.252.0
    broadcast 144.aa.bb.255
    gateway 144.aa.bb.1

# vlan 321
auto eth0.321
allow-hotplug eth0.321
iface eth0.321 inet static
    address 144.aa.cc.34
    netmask 255.255.254.0
    broadcast 144.aa.cc.255
    gateway 144.aa.cc.1
    vlan-raw-device eth0

auto eth0.321:0
allow-hotplug eth0.321:0
iface eth0.321:0 inet static
    address 10.aa.cc.34
    netmask 255.255.254.0
    broadcast 10.aa.cc.255
    gateway 10.aa.cc.1

The routing table is:
# netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.aa.bb.1      0.0.0.0         UG        0 0          0 eth0
10.aa.bb.0      0.0.0.0         255.255.252.0   U         0 0          0 eth0
10.aa.cc.0      0.0.0.0         255.255.254.0   U         0 0          0 eth0.321
144.aa.cc.0     0.0.0.0         255.255.254.0   U         0 0          0 eth0.321
144.aa.bb.0     0.0.0.0         255.255.252.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0

The Cisco switch port is trunked and configuration is
interface Ethernet1/42
  description Desktop_datacentre
  switchport mode trunk
  switchport trunk native vlan 322
  switchport trunk allowed vlan 321-322
  spanning-tree port type edge trunk
  no shutdown

Observium sees this trunked port like on this image



Test by pinging all 4 gateways:
# fping 10.aa.bb.1 10.aa.cc.1 144.aa.bb.1 144.aa.cc.1
10.aa.bb.1 is alive
10.aa.cc.1 is alive
144.aa.bb.1 is alive
144.aa.cc.1 is alive

Back to the main page