Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Keeping groups apart on one switch (VLANs)

After this lesson: I can keep two groups of hosts apart on one switch.

55 min lesson6 commandsVLAN lab: VLANs and inter-VLAN routing on one Ubuntu VM in your browser

Tills and guests on one switch

One office switch connects the tills, the staff PCs and a box for guest wifi. A guest laptop should never see a till.

Buying three switches costs money and wall space. A VLAN splits one switch into several separate ones, using only settings.

By the end of this lesson

Note

I can keep two groups of hosts apart on one switch.

Key words

WordWhat it meansExample
Broadcast domainall the devices that hear each other's broadcasts
VLANa virtual LAN: one switch acting as several separate onesVLAN 10
Access porta switch port that belongs to one VLAN, for one device
Trunk porta switch port that carries several VLANs between switches or to a router
Taga label on a frame that names its VLAN
Router on a stickone router cable that carries every VLAN

The cells students fill in are left blank in this preview.

One switch is one broadcast domain

A switch passes a broadcast out of every port. So every device on a plain switch hears every other.

That is called a broadcast domain. Devices in the same one can reach each other with no router.

A VLAN cuts the switch into several broadcast domains.

Meet the switch, the router and the hosts

Command
vlanlab status

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Read the switch's VLAN table

Command
sudo ip netns exec sw bridge vlan show

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Ask across the switch, with no router

Command
sudo ip netns exec h20 arping -c 2 -I eth0 10.10.0.100

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the three answers say

Every port is in VLAN 1. The VLAN table has one line for each of the four ports and one for the bridge itself, br0. The hosts belong to two address ranges, but the switch treats them as one group.

The arping asks "who has this address?" straight across the switch. The server answers both times, with its own hardware address. Nothing separates the two groups yet.

Access ports and trunk ports

An access port belongs to one VLAN. The device plugged into it knows nothing about VLANs.

A trunk port carries several VLANs on one cable. To keep them apart, each frame gets a tag that names its VLAN. The standard for this is called 802.1Q.

Worked example: a port table

PortPlugged intoModeVLANs
1Till oneAccess10
2Till twoAccess10
3Staff PCAccess20
4Guest wifi boxAccess30
5The routerTrunk10, 20, 30

The cells students fill in are left blank in this preview.

A router joins the VLANs

Devices in different VLANs cannot talk through the switch. If they must talk, a router has to sit between them.

One cable is enough. It is a trunk, and the router gives it one subinterface for each VLAN. Each subinterface has the gateway address of its VLAN.

This is a router on a stick.

Worked example: a packet across VLANs

StepWhereTag
1Staff PC sends to its gatewayNone
2Switch sends it to the routerVLAN 20
3Router finds the till's network and sends it backVLAN 10
4Switch hands it to the tillNone

The cells students fill in are left blank in this preview.

Read where h10 sends other networks

Command
sudo ip netns exec h10 ip route

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Try to reach the other VLAN

Command
sudo ip netns exec h10 ping -c 2 -W 1 10.20.0.11

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Look at the router's one cable

Command
sudo ip netns exec r1 ip -br addr show dev eth0

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A common mistake

Warning

Many people think hosts in different VLANs can still reach each other through the switch. The switch never crosses a VLAN. A router must join them, and a rule on that router can still block the traffic.

Going further: a third group

The shop adds door cameras. They go in VLAN 40, on port 6, with the network 10.40.0.0/24.

Write the new and changed rows of the worked port table. Say what gateway address the router's new subinterface needs.

Then add the rows to PORTS in a copy of the tests. Check with can_talk that a camera reaches a till only through the router.

About this lab and its source: VLAN lab: VLANs and inter-VLAN routing on one Ubuntu VM in your browser

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.