Occasionally it is necessary to segment networks into VLANs (Virtual LAN). VLANs are a layer 2 technology which allow for segregation of broadcast domains. VLANs help to logically separate different types of traffic. Segmenting network traffic into data, VoIP, and/or Video Streams can help to provide better manageability and security. VLANs are typically applied at a network switch port by specifying the exact VLAN data and Voice traffic can use, but can also be specified at a Linux virtual port adapter and the network switch can enable 802.1q trunking.

This guide will help in setting up VLANs through editing of Linux configuration files.

 

The things you will need before starting:

  • An understating of basic network configurations
  • Access to a Debian-based Linux Desktop or Server
  • Access to the root account or an account with sudo access.
  • Basic knowledge of text editing software such as Vi, Vim, Nano, Pico, Gedit, etc.

Steps:

  1. Log in as either root or a user with sudo access.
  2. Install the vlan package
    sudo apt-get install vlan
  3. Edit your the /etc/modules file to add the kernel module 8021q to the last line
    sudo vi /etc/modules
  4. The location of the configuration file is /etc/network/interfaces
    sudo vi /etc/network/interfaces
  5. Once the file is open, the document will look similar to this:
    auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 inet dhcp
  6. We want to edit the configuration file to look more like this:
    auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 inet dhcp

    auto eth0.2
    iface eth0.2 inet dhcp
    (because the network adapter is called by name it is not necessary to specify)
    or
    auto vlan2
    iface vlan2 inet dhcp
    vlan-raw-device eth0
    (it is necessary to specify which network adapter you want to apply this to because it is not already called out by name)
  7. Once the files have been edited, save, and restart the networking deamon
    sudo /etc/init.d/networking restart
    or reboot the desktop/server
    sudo reboot

You can now set static IP addressed manually to these VLAN adapters so that they do not rely on DHCP.