Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Ubuntu - Connect To VLAN

VLAN stands for virtual-LAN and it can be a great way to segregate machines virtually for security. If you have a smart switch, or a good router, it should be able to specify individual or combinations of VLANs that are allowed to connect on specific physical ports. For more in-depth information about VLANs, visit the the wikipedia page.

In an ideal world, your computer would connect to a "smart" switch, which would then apply the necessary vlan tags to frames that go off to the network device that is using VLANs to separate ports, but this tutorial is here to help you if you need to connect your linux computer directly to a port that requires a VLAN.

This tutorial was tested on Ubuntu 20.04

Steps

Install Packages

Install the vlan package:

sudo apt-get install vlan

The vlan package downloaded the 8021q kernel module that you need to use in order to connect to a vlan. To immediately have the kernel module applied so you can make use of it, run:

sudo modprobe 8021q

To make the change permanent, use the following command to load the module at boot.

sudo su -c 'echo "8021q" >> /etc/modules'

Configure Network

Network Manager GUI

The quick-and-easy way to get going is to:

  1. Click on your network manager
  2. Select Edit Connections... from the dropdown.
  3. Click the + icon in the bottom-left corner to add a new item.
  4. Click on the dropdown menu and change it from the default of Ethernet to VLAN (just above VPN).
  5. Click Create
  6. For the Parent interface, choose the NIC that you are using to connect. This is the one called enp3s0 or eth0 or similar.
  7. For the VLAN id: enter the ID of your VLAN. You should know this or have been given it by your network administrator.
  8. Feel free to give the interface a name and click Save.

You should now be able to connect to your VLAN.

Netplan Configuration

Here is an example netplan configuration that makes use of vlan ID 3. It should work in theory, but it hasn't for me when I was testing. I am leaving it here for my next attempt.

# Manual settings using vlan on DHCP
network:
  version: 2
  renderer: networkd
  ethernets: 
    enp2s0f0:
      dhcp4: yes
  vlans:
    vlan3:
      id: 3
      link: enp2s0f0

References

Last updated: 8th August 2020
First published: 1st August 2020