Concepts / Switches

Switches

Hub

Also called repeater, collision domain, half duplex

The switch's ancestor: it repeats every frame out of every port, so everyone hears everything.

The problem

A hub sends every frame to every port, so each device hears traffic meant for the others.

  1. Alice (10.0.1.10), bob (10.0.1.11) and carol (10.0.1.12) each have one cable to the same box.
  2. Alice pings bob. A hub keeps no table, so it copies her frame out of bob's port and carol's.
  3. Bob's reply is copied to alice and carol the same way: carol hears both sides.
  4. Only one device can send at a time; two at once collide, so everyone shares the wire (half duplex).
Hub, switch, router: who hears what
Hub, switch, router: who hears what

A hub repeats every frame out of every port, so everyone hears everything; a switch sends a frame only to the port behind its destination.

What you'd see

$ tcpdump -e -nn -i eth0 icmp
18:49:15.165904 b6:a0:12:30:a8:0b > 06:c7:51:36:4e:b8, ethertype IPv4 (0x0800), length 98: 10.0.1.10 > 10.0.1.11: ICMP echo request, id 68, seq 1, length 64
18:49:15.165918 06:c7:51:36:4e:b8 > b6:a0:12:30:a8:0b, ethertype IPv4 (0x0800), length 98: 10.0.1.11 > 10.0.1.10: ICMP echo reply, id 68, seq 1, length 64
18:49:16.224820 b6:a0:12:30:a8:0b > 06:c7:51:36:4e:b8, ethertype IPv4 (0x0800), length 98: 10.0.1.10 > 10.0.1.11: ICMP echo request, id 68, seq 2, length 64
18:49:16.224848 06:c7:51:36:4e:b8 > b6:a0:12:30:a8:0b, ethertype IPv4 (0x0800), length 98: 10.0.1.11 > 10.0.1.10: ICMP echo reply, id 68, seq 2, length 64
  • Recorded on carol, with the switch told to forget every MAC at once (ageing_time 0), so it floods everything like a hub.
  • b6:a0:… > 06:c7:…: from alice's card to bob's. Carol's MAC is in neither field, yet the frame reached her.
  • echo request and echo reply: she hears both directions of a conversation she is not part of.

Guess first

Carol runs the same recording on a normal switch that has learned alice and bob. What does she see?

Show answer

Nothing: the switch sends alice's frames only to bob's port and bob's only to alice's. That is why sniffing works on a hub and not on a switch.

In short

A hub has no table and makes no decisions: a frame in on one port goes out of all the others, and only one device can talk at a time (one collision domain, half duplex). A switch learns which address is behind which port and sends each frame only where it belongs. That is also why sniffing works on a hub and not on a switch, unless the switch is tricked into flooding (MAC flooding) or the attacker gets in the middle.

See it on real machines

Read next

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab