Chapters

Hubs, switches & routers

Chapter 6 showed the office router and switch as boxes on a map. This chapter opens them up: what a hub, a switch and a router each do with an arriving frame, how a switch learns where devices are, and why routers are the walls that keep broadcasts contained.

Network building blocks · chapter 32 of 34 · 7 min read

Hub: repeat everything (layer 1)

A hub is the simplest device. It has no intelligence: any signal arriving on one port is repeated out of every other port. It does not read MAC or IP addresses; it only copies electrical signals, so it works at layer 1 (chapter 11).

HubA · senderB · ignores itC · targetD · ignores itcopied to every port

B and D receive the frame, see a destination MAC that is not theirs (chapter 7), and drop it. The bandwidth was used anyway.

Wide by design - scroll it sideways.

  • One shared medium. Only one device can send at a time. If two send at once, the signals collide and both must retry after a random wait (the old Ethernet rule called CSMA/CD).
  • Half duplex: send or receive, never both at once.
  • Everyone sees everything: any device can capture all traffic on the hub.

All devices on a hub are one collision domain. With more devices, collisions grow quickly and throughput falls apart. Hubs are obsolete; you will meet the idea mostly in exams and old buildings.

Switch: learn, then forward (layer 2)

A switch is the smart replacement. It reads each frame's MAC addresses (layer 2) and keeps a MAC address table: which MAC lives behind which port. It builds that table by itself:

#StepWhat the switch does
1LearnA frame arrives on port 3 from MAC 3c:7c:3f:10:22:01, so that MAC is behind port 3. Write it down.
2Look upFind the destination MAC in the table
3aForwardKnown: send it out of that one port only
3bFloodUnknown, or the broadcast MAC ff:ff:ff:ff:ff:ff: send it out of every port except the one it came in on
4Age outForget entries not seen for a while (typically 5 minutes), so moved devices are relearned
Floods happen only until the switch has heard from a device once. After that, traffic between two ports touches no other port.
  • Every port is its own collision domain, and links are full duplex: send and receive at once, no collisions at all.
  • Many conversations at once: A ↔ B and C ↔ D run in parallel at full speed.
  • Switches do not change frames and have no IP address on the data path (managed switches have one for their admin page).

Router: between networks (layer 3)

A router connects different networks. It reads the destination IP address (layer 3) and uses its routing table to pick the next hop (chapter 12). Switches move frames within a network; routers move packets between networks. On the way through, a router:

1Accepts only frames addressed to its own MAC (the "gateway" MAC the sender found with ARP, chapter 9)
2Removes the frame, reads the IP header, looks up the destination network (longest prefix match)
3Lowers the TTL and updates the checksum; may NAT (chapter 10) and filter (firewall)
4Builds a new frame on the outgoing interface, with its own MAC as source and the next device's MAC as destination
5Does not forward broadcasts (section 7)

Watch frames move through a network

Here is a small version of Kadé's office. The staff network uses a switch; imagine the warehouse still had an old hub. Pick a sender and a receiver, send frames, and watch the switch learn. (ARP is assumed to be already done.)

From
To
Office routerSwitch (staff)Hub (warehouse)Front desk PC172.16.1.10Office printer172.16.1.20Staff laptop172.16.1.30Stock scanner172.16.2.10Packing PC172.16.2.11Label printer172.16.2.20eth1 e4:8d:8c:00:01:01eth2 e4:8d:8c:00:01:02
  • forwarded to one port
  • flooded / repeated to all
  • accepted · ignored (got a copy) · sender, written under each device

Try: send Front desk → Printer twice (flood, then forward), then Printer → Front desk. Then send inside the warehouse and compare.

Switch MAC tablePortDevice
empty: the switch has learned nothing yet

Hub, switch and router compared

#HubSwitchRouter
1Layer1 · physical2 · data link3 · network
2Readsnothing (signals)MAC addressesIP addresses
3Keeps a table of-MAC → port (learned)network → next hop (routes)
4Sends a frame toevery portthe right port (floods if unknown)the next hop, in a new frame
5Connectsdevices, in one networkdevices, in one networknetworks
6Collision domainsone for all portsone per portone per port
7Broadcast domainsoneone (per VLAN, section 8)one per interface: it separates them
8Duplexhalffullfull
9Changes the packet?nonoyes: TTL, checksum, MACs, maybe NAT
10Todayobsoleteeverywhere inside networksevery network edge
Your home "router" is really a router, a small switch (the LAN ports) and a WiFi access point in one box. An access point acts like a switch port for wireless devices, bridging WiFi into the wired network. A layer 3 switch is a switch that can also route between VLANs at full speed.

Who a frame is for: unicast, broadcast, multicast

#KindDestination MACA switch sends it toExamples
1Unicastone device's MACthat device's port (once learned)Almost everything: HTTP, SSH, DB queries
2Broadcastff:ff:ff:ff:ff:ffevery portARP requests (chapter 9), DHCP Discover (chapter 27)
3Multicasta group MAC, e.g. 01:00:5e:… (IPv4) or 33:33:… (IPv6)every port, unless the switch tracks group members (IGMP snooping)IPv6's NDP (chapter 30), video to many screens
The fourth kind from chapter 12, anycast, happens at the routing level: to a switch it looks like normal unicast.

Broadcast domains

A broadcast reaches every device in its network, but routers do not forward broadcasts. Everything a broadcast can reach is one broadcast domain. In the office, the router makes two:

broadcast domain 1 · staff 172.16.1.0/24broadcast domain 2 · warehouse 172.16.2.0/24Routerthe wallSwitchFront desksends ARPPrinterLaptopSwitchScannerPacking PCLabel printerARP broadcast reaches every staff device……and stops here at the router ✕

Wide by design - scroll it sideways.

This is a big reason to split large networks into subnets (chapter 3). In one flat network of 2,000 devices, every ARP request and DHCP Discover interrupts all 2,000; as devices multiply, background broadcast traffic grows until the network slows down. Subnets keep each broadcast domain small, and give a router a place to apply firewall rules between groups.

VLANs: several networks on one switch

Buying a separate switch for every network gets expensive. A managed switch can be split into VLANs (virtual LANs): ports 1-8 belong to VLAN 10 (staff), ports 9-16 to VLAN 20 (warehouse). They behave like two separate switches: separate MAC tables and separate broadcast domains. Traffic between VLANs must go through a router, like any traffic between networks.

Access portBelongs to one VLAN; the connected device knows nothing about VLANs (a PC, a printer)
Trunk portCarries many VLANs on one cable, each frame marked with a 4-byte VLAN tag (802.1Q). Used between switches, and to the router ("router on a stick": one cable, one sub-interface per VLAN).
Guest WiFiA classic use: visitors on their own VLAN, reaching the internet but never the office printers or PCs
In GCP, a VPC plays this role: separate subnets without any switch configuration, and no broadcast at all (chapter 9).

Loops and spanning tree

People often connect switches with two cables for backup. Without protection, that creates a loop, and a single broadcast circles forever, since Ethernet frames have no TTL (chapter 12). Each switch floods it again, copies multiply, and within seconds the whole network is saturated: a broadcast storm.

Managed switches run Spanning Tree Protocol (STP, or its faster version RSTP): they talk to each other, find loops, and block the extra links, keeping them as backups that switch on if the main path fails. Cheap unmanaged switches usually lack it, which is how one wrong cable in a small office can take everything down.

The full journey, device by device

Putting it together: the front desk PC (staff network) prints a shipping label on the warehouse label printer (172.16.2.20):

#DeviceReadsFrame src → dst MACDoes
1Front desk PCits maskfront desk → router eth1Sees 172.16.2.20 is another network, so sends to the gateway (chapters 4-5)
2Staff switchMACs(unchanged)Forwards out of the router's port only
3RouterIProuter eth2 → label printerRoutes to eth2, lowers TTL, builds a new frame
4Warehouse switchMACs(unchanged)Forwards out of the label printer's port only
5Label printereverything-Its MAC and IP match: unwraps up to the print job (chapter 11)
The source and destination IP stay the same end to end. The MACs change at the router, and only there, exactly as in chapter 8's hop explorer.

Summary

#IdeaIn one lineNew terms
1HubLayer 1; repeats everything; one collision domain; half duplex; obsoletehub, collision domain, CSMA/CD
2SwitchLayer 2; learns MAC → port; forwards or floods; full duplexMAC address table, flooding
3RouterLayer 3; routes between networks; rewrites MACs; stops broadcasts
6CastingUnicast, broadcast (ff:ff…), multicast (group MACs)IGMP snooping
7Broadcast domainEverything a broadcast reaches; routers are the edges; keep them smallbroadcast domain
8VLANsSplit one switch into separate networks; trunks carry tagged framesVLAN, 802.1Q, trunk
9LoopsRedundant links cause broadcast storms; STP blocks the extrasbroadcast storm, STP

Try it yourself

All broadcast and multicast frames in your broadcast domain

  • What to look for: ARP, DHCP, mDNS (01:00:5e:00:00:fb), IPv6 NDP (33:33:…).
  • From section: 7. Broadcast domains
sudo tcpdump -n -e -i en0 broadcast or multicast

Unicast frames that reached you

sudo tcpdump -n -e -i en0 not broadcast and not multicast

The routers on your path

traceroute 1.1.1.1

A real switch's learned table

show mac address-table

Which ports belong to which VLAN

show vlan brief

Spotted a mistake, or something unclear? Suggest an edit on GitHub