Switching
Learn MACs, flood unknowns, forward knowns, filter the rest. CAM tables and STP.
Level: intermediate
What is it?
Ethernet switching forwards frames among ports using a forwarding database that associates MAC addresses with ports within a VLAN. Switches learn from source addresses, forward known destinations, and flood certain unknown or broadcast traffic when required by the protocol and configuration.
Why does it matter?
Switching lets many hosts share a local network without sending every unicast frame to every port. Loop prevention, VLANs, and correct MAC learning help keep the layer-2 topology stable.
Mental model
A switch learns where a sender is located from the source MAC, then uses the destination MAC to decide where the frame should go. It does not need to interpret the application payload for basic forwarding.
How it works
- The forwarding table is learned dynamically and can age out entries.
- Unknown unicast and broadcast flooding is scoped to the relevant VLAN.
- Redundant layer-2 links can create loops; spanning-tree mechanisms block some paths to maintain a loop-free topology.
- VLANs partition broadcast domains and require consistent access/trunk configuration.
- Switching and routing operate at different logical layers, though multilayer devices combine them.
Steps
- A frame enters on port 3 with source MAC A and destination MAC B.
- The switch learns that A is reachable through port 3.
- If B's location is known, it forwards only to that port; otherwise it floods eligible ports in the VLAN.
- When B replies, the switch learns B's port and subsequent forwarding is more selective.
Real-world usage
- Debugging MAC-table learning, loops, and unknown-unicast flooding.
- Understanding VLAN access and trunk ports.
- Interpreting spanning-tree port states.
Common mistakes
- Assuming a basic layer-2 switch can route between subnets without a layer-3 interface/function.
- Expecting the MAC table to be global across unrelated VLANs.
- Ignoring loops that can multiply broadcast traffic.
Interview questions
How does a switch learn a MAC address?
It records the source MAC address and ingress port from received frames, scoped to the relevant VLAN.
Why is spanning tree useful?
It helps prevent persistent layer-2 forwarding loops when redundant links exist.