---
title: "Switching and VLANs"
domain: networking
level: beginner
duration: "2h 30min total"
---

# Switching and VLANs

Inside a building or a data centre, most traffic never touches a router: switches move it between devices on the same network. This module explains how a switch learns where devices are, how **virtual LANs (VLANs)** split one physical switch into separate networks, how traffic moves between VLANs, why loops are dangerous and how the Spanning Tree Protocol prevents them, and which Layer 2 attacks you need to defend against.

## Learning objectives
By the end of this module you will be able to:
1. Explain how a switch learns MAC addresses, forwards and floods frames, and what a broadcast domain is.
2. Describe VLANs, IEEE 802.1Q tagging, and the difference between access and trunk ports.
3. Compare inter-VLAN routing options: router-on-a-stick and Layer 3 switches.
4. Explain why switching loops happen and what the Spanning Tree Protocol (STP) and Rapid STP do about them.
5. Assess Layer 2 attacks (MAC flooding, VLAN hopping) and the defences against them (port security, trunk hardening).

## Prerequisites
- [04 — The OSI Model](../04-osi-model/README.md) and [06 — Subnetting](../06-subnetting/README.md).
- For the lab: a Linux machine or virtual machine (VM) with `sudo`, the `ip` and `bridge` commands (iproute2) and `tcpdump`.

## Contents
| Type | Duration |
|---|---|
| [Theory](lesson.md) | 50 min |
| [Hands-on lab: building a VLAN-aware switch with Linux namespaces](lab.md) | 60 min |
| [Assessment (10 questions)](quiz.md) | 15 min |

## Further reading
- IEEE 802.1Q — Bridges and Bridged Networks (VLAN tagging; also includes the Rapid and Multiple Spanning Tree protocols)
- IEEE 802.1D — MAC Bridges (original Spanning Tree Protocol)
- [Linux bridge documentation](https://docs.kernel.org/networking/bridge.html)
