1. Home
  2. Configure VLANs on Raspberry Pi

Configure VLANs on Raspberry Pi

This article explains how to configure VLANs on Raspberry Pi. To configure VLANs on Raspberry Pi, you’ll need to give it access to both the main and VLAN interfaces. You can do this by executing the following steps:


1. Install VLAN package and configure modules:

sudo apt-get install vlan
sudo su
echo 8021q >> /etc/modules
exit

2. Create and edit the file /etc/network/interfaces.d/vlans

 
E.g. if you want to add the VLAN ID 10 and VLAN ID 20 add the following content to the file
 

auto eth0.10
iface eth0.10 inet manual
  vlan-raw-device eth0
  
auto eth0.20
iface eth0.20 inet manual
  vlan-raw-device eth0

* By convention, a VLAN virtual NIC should follow the naming convention:

<physicalNIC>.<PVID>

If you have multiple VLANs, you can just add them all to that same VLAN file, following the same format.

3. Configure static IP addresses to the new virtual interfaces by editing the file /etc/dhcpcd.conf :

# Example of static IP configuration:

interface eth0
static ip_address=10.0.20.125/24
static routers=10.0.20.1
static domain_name_servers=1.1.1.1
#static domain_search=

interface eth0.10
static ip_address=10.0.10.125/24
static routers=10.0.10.1
static domain_name_servers=1.1.1.1

interface eth0.20
static ip_address=10.0.20.125/24
static routers=10.0.20.1
static domain_name_servers=1.1.1.1

4 – Reboot the Raspberry the interface eth0.10 and eth0.20 should be up automatically now:

sudo ifconfig
eth0.10: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.10.125  netmask 255.255.255.0  broadcast 10.0.10.255
        inet6 fe80::ba27:ebff:fe10:7013  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:10:70:13  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3102  bytes 134060 (130.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0.20: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.20.125  netmask 255.255.255.0  broadcast 10.0.20.255
        inet6 fe80::ba27:ebff:fe10:7013  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:10:70:13  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3102  bytes 134060 (130.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

This article explains how to configure VLANs on Raspberry Pi. Learn more about configuring Domotz on Raspberry Pi. Learn more about running Raspberry Pi as your agent platform.

Updated on December 29, 2022

Was this article helpful?