Switching, VLANs & STP
How Layer 2 really works in a LAN
01Collision vs broadcast domains
A hub shares one collision domain. A switch gives each port its own collision domain. A VLAN or router separates broadcast domains. Modern switches = many collision domains, one broadcast domain per VLAN.
02MAC learning
Switches build a MAC address table by reading source MACs of incoming frames. Entries age out (default 300s). Unknown unicast is flooded.
What a switch actually does
A switch is a box with many ports. It learns which device is on which port, then sends each frame only where it needs to go.
| MAC | Port |
|---|---|
| empty | |
03802.1Q tagging
VLAN tag inserted into Ethernet frame: 4 bytes (TPID 0x8100 + PCP/DEI + 12-bit VLAN ID). Access ports untag; trunk ports tag. Native VLAN on a trunk is untagged.
04STP/RSTP
Elects a root bridge, blocks redundant ports to prevent loops, recomputes on topology change. RSTP converges in seconds; STP in 30-50s.
05Port security
Limits MACs per port, shuts down or restricts on violation. First line of defense against rogue devices.