The box with the blinking lights behind your router, or the ports on the back of the router itself, is a switch. Plug in four laptops and they can all talk. Nobody configured anything.
Yet a switch does not send every frame to every port. If laptop A talks to laptop B, laptop C normally never sees it. How does the switch know where B is, when nobody told it?
The MAC table
A switch keeps one table: which MAC address lives on which port. It starts empty. It fills it with one simple rule, applied to every frame that comes in:
- Learn: write down the frame’s source MAC and the port it came in on.
- Look up the frame’s destination MAC in the table.
- Broadcast, or not in the table: flood it out of every port except the one it came in on.
- In the table: forward it out of that one port only.
- On the same port it came in on: drop it (filter), since the receiver already had it.
Watch it happen. laptop-a pings laptop-b, and the switch has never seen any of them before. Keep the Tables view open in another step to see the MAC table grow.
A switch with an empty table
-
laptop-a: ping -c 1 192.168.1.11
laptop-a runs ping -c 1 192.168.1.11. laptop-a knows the IP address 192.168.1.11 but not its MAC address, so it asks everyone on the network: who has 192.168.1.11?
- Time
- 0 µs
- Cable
- laptop-a eth0 → sw1 1
- Ethernet
- 02:00:00:00:00:0a → ff:ff:ff:ff:ff:ff (broadcast)
- ARP
- who has 192.168.1.11? tell 192.168.1.10
- On the wire
- 64 bytes
- laptop-a ARP cache
- 192.168.1.11: asking (INCOMPLETE)
-
sw1 sends a broadcast out of every other port
The switch has never seen laptop-a. It writes down: 02:00:00:00:00:0a lives on port 1. The frame is a broadcast, so it goes out of every other port.
- Time
- 100.512 µs
- Cable
- sw1 2 → laptop-b eth0 (+2 more)
- Ethernet
- 02:00:00:00:00:0a → ff:ff:ff:ff:ff:ff (broadcast)
- ARP
- who has 192.168.1.11? tell 192.168.1.10
- On the wire
- 64 bytes
- sw1 MAC table
- learned 02:00:00:00:00:0a → port 1
-
laptop-b: ARP: 192.168.1.11 is at 02:00:00:00:00:0b
Only laptop-b answers. laptop-c and laptop-d read the question, saw it was not about them, and stayed quiet.
- Time
- 201.024 µs
- Cable
- laptop-b eth0 → sw1 2
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- ARP
- 192.168.1.11 is at 02:00:00:00:00:0b
- On the wire
- 64 bytes
- laptop-b ARP cache
- 192.168.1.10 is at 02:00:00:00:00:0a
-
sw1 forwards it out of port 1 only
sw1 writes down where 02:00:00:00:00:0b is: port 2. sw1 knows 02:00:00:00:00:0a is on port 1, so only that port gets the frame.
- Time
- 301.536 µs
- Cable
- sw1 1 → laptop-a eth0
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- ARP
- 192.168.1.11 is at 02:00:00:00:00:0b
- On the wire
- 64 bytes
- sw1 MAC table
- learned 02:00:00:00:00:0b → port 2
-
laptop-a: ICMP echo request seq=1 192.168.1.10 → 192.168.1.11
laptop-a sends an ICMP echo request ("are you there?") to 192.168.1.11, in a frame addressed to laptop-b. laptop-a saves it in its ARP cache: 192.168.1.11 is at 02:00:00:00:00:0b.
- Time
- 402.048 µs
- Cable
- laptop-a eth0 → sw1 1
- Ethernet
- 02:00:00:00:00:0a → 02:00:00:00:00:0b
- IP
- 192.168.1.10 → 192.168.1.11
- TTL
- 64
- ICMP
- echo request, seq 1
- On the wire
- 102 bytes
- laptop-a ARP cache
- 192.168.1.11 is at 02:00:00:00:00:0b
-
sw1 forwards it out of port 2 only
sw1 knows 02:00:00:00:00:0b is on port 2, so only that port gets the frame.
- Time
- 502.864 µs
- Cable
- sw1 2 → laptop-b eth0
- Ethernet
- 02:00:00:00:00:0a → 02:00:00:00:00:0b
- IP
- 192.168.1.10 → 192.168.1.11
- TTL
- 64
- ICMP
- echo request, seq 1
- On the wire
- 102 bytes
-
laptop-b: ICMP echo reply seq=1 192.168.1.11 → 192.168.1.10
laptop-b answers with an echo reply.
- Time
- 603.68 µs
- Cable
- laptop-b eth0 → sw1 2
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- IP
- 192.168.1.11 → 192.168.1.10
- TTL
- 64
- ICMP
- echo reply, seq 1
- On the wire
- 102 bytes
-
sw1 forwards it out of port 1 only
sw1 knows 02:00:00:00:00:0a is on port 1, so only that port gets the frame.
- Time
- 704.496 µs
- Cable
- sw1 1 → laptop-a eth0
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- IP
- 192.168.1.11 → 192.168.1.10
- TTL
- 64
- ICMP
- echo reply, seq 1
- On the wire
- 102 bytes
-
laptop-a receives ICMP echo reply seq=1 192.168.1.11 → 192.168.1.10
laptop-a gets the frame. The reply arrived 0.805 ms after the request left: that is the round-trip time. laptop-a prints: rtt min/avg/max/mdev = 0.805/0.805/0.805/0.000 ms
- Time
- 805.312 µs
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- IP
- 192.168.1.11 → 192.168.1.10
- TTL
- 64
- ICMP
- echo reply, seq 1
- On the wire
- 102 bytes
At the end, the switch knows two MAC addresses. laptop-c and laptop-d are not in its table yet: they have not sent anything. The moment they do, the switch learns them too.
This lab carries a capture check: the course build ran four real Linux computers on a Linux software switch, sent the same ping, and recorded what laptop-a and laptop-c received. laptop-c’s recording had exactly one frame, the broadcast, just like the lab.
What does each laptop see?
tcpdump is a tool that prints every frame a computer’s network card receives. Here it runs on laptop-c while laptop-a pings laptop-b. (The -n asks it to print addresses as numbers.)
What laptop-c sees on a switch
-
laptop-c: tcpdump -n
laptop-c runs tcpdump -n.
- Time
- 0 µs
-
laptop-a: ping -c 1 192.168.1.11
laptop-a runs ping -c 1 192.168.1.11. laptop-a knows the IP address 192.168.1.11 but not its MAC address, so it asks everyone on the network: who has 192.168.1.11?
- Time
- 0 µs
- Cable
- laptop-a eth0 → sw1 1
- Ethernet
- 02:00:00:00:00:0a → ff:ff:ff:ff:ff:ff (broadcast)
- ARP
- who has 192.168.1.11? tell 192.168.1.10
- On the wire
- 64 bytes
- laptop-a ARP cache
- 192.168.1.11: asking (INCOMPLETE)
-
sw1 sends a broadcast out of every other port
sw1 writes down where 02:00:00:00:00:0a is: port 1. The frame is for ff:ff:ff:ff:ff:ff, everyone on the network, so sw1 sends a copy out of every port except the one it came in on (2, 3, 4).
- Time
- 100.512 µs
- Cable
- sw1 2 → laptop-b eth0 (+2 more)
- Ethernet
- 02:00:00:00:00:0a → ff:ff:ff:ff:ff:ff (broadcast)
- ARP
- who has 192.168.1.11? tell 192.168.1.10
- On the wire
- 64 bytes
- sw1 MAC table
- learned 02:00:00:00:00:0a → port 1
-
laptop-b: ARP: 192.168.1.11 is at 02:00:00:00:00:0b
laptop-b answers only the one who asked: 192.168.1.11 is at 02:00:00:00:00:0b. laptop-b saves it in its ARP cache: 192.168.1.10 is at 02:00:00:00:00:0a.
- Time
- 201.024 µs
- Cable
- laptop-b eth0 → sw1 2
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- ARP
- 192.168.1.11 is at 02:00:00:00:00:0b
- On the wire
- 64 bytes
- laptop-b ARP cache
- 192.168.1.10 is at 02:00:00:00:00:0a
-
sw1 forwards it out of port 1 only
sw1 writes down where 02:00:00:00:00:0b is: port 2. sw1 knows 02:00:00:00:00:0a is on port 1, so only that port gets the frame.
- Time
- 301.536 µs
- Cable
- sw1 1 → laptop-a eth0
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- ARP
- 192.168.1.11 is at 02:00:00:00:00:0b
- On the wire
- 64 bytes
- sw1 MAC table
- learned 02:00:00:00:00:0b → port 2
-
laptop-a: ICMP echo request seq=1 192.168.1.10 → 192.168.1.11
laptop-a sends an ICMP echo request ("are you there?") to 192.168.1.11, in a frame addressed to laptop-b. laptop-a saves it in its ARP cache: 192.168.1.11 is at 02:00:00:00:00:0b.
- Time
- 402.048 µs
- Cable
- laptop-a eth0 → sw1 1
- Ethernet
- 02:00:00:00:00:0a → 02:00:00:00:00:0b
- IP
- 192.168.1.10 → 192.168.1.11
- TTL
- 64
- ICMP
- echo request, seq 1
- On the wire
- 102 bytes
- laptop-a ARP cache
- 192.168.1.11 is at 02:00:00:00:00:0b
-
sw1 forwards it out of port 2 only
sw1 knows 02:00:00:00:00:0b is on port 2, so only that port gets the frame.
- Time
- 502.864 µs
- Cable
- sw1 2 → laptop-b eth0
- Ethernet
- 02:00:00:00:00:0a → 02:00:00:00:00:0b
- IP
- 192.168.1.10 → 192.168.1.11
- TTL
- 64
- ICMP
- echo request, seq 1
- On the wire
- 102 bytes
-
laptop-b: ICMP echo reply seq=1 192.168.1.11 → 192.168.1.10
laptop-b answers with an echo reply.
- Time
- 603.68 µs
- Cable
- laptop-b eth0 → sw1 2
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- IP
- 192.168.1.11 → 192.168.1.10
- TTL
- 64
- ICMP
- echo reply, seq 1
- On the wire
- 102 bytes
-
sw1 forwards it out of port 1 only
sw1 knows 02:00:00:00:00:0a is on port 1, so only that port gets the frame.
- Time
- 704.496 µs
- Cable
- sw1 1 → laptop-a eth0
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- IP
- 192.168.1.11 → 192.168.1.10
- TTL
- 64
- ICMP
- echo reply, seq 1
- On the wire
- 102 bytes
-
laptop-a receives ICMP echo reply seq=1 192.168.1.11 → 192.168.1.10
laptop-a gets the frame. The reply arrived 0.805 ms after the request left: that is the round-trip time. laptop-a prints: rtt min/avg/max/mdev = 0.805/0.805/0.805/0.000 ms
- Time
- 805.312 µs
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- IP
- 192.168.1.11 → 192.168.1.10
- TTL
- 64
- ICMP
- echo reply, seq 1
- On the wire
- 102 bytes
-
laptop-c: tcpdump shows what it saw
laptop-c prints: 1 packet captured
- Time
- 1.805 ms
One line: the broadcast question. The ping and its reply went past laptop-c’s port without it ever knowing.
A hub: everyone sees everything
Before switches were cheap, networks used hubs. A hub does not read addresses at all. Whatever arrives on one port, it repeats out of all the others. Same laptops, same ping, a hub in the middle:
What laptop-c sees on a hub
-
laptop-c: tcpdump -n
laptop-c runs tcpdump -n.
- Time
- 0 µs
-
laptop-a: ping -c 1 192.168.1.11
laptop-a runs ping -c 1 192.168.1.11. laptop-a knows the IP address 192.168.1.11 but not its MAC address, so it asks everyone on the network: who has 192.168.1.11?
- Time
- 0 µs
- Cable
- laptop-a eth0 → hub1 1
- Ethernet
- 02:00:00:00:00:0a → ff:ff:ff:ff:ff:ff (broadcast)
- ARP
- who has 192.168.1.11? tell 192.168.1.10
- On the wire
- 64 bytes
- laptop-a ARP cache
- 192.168.1.11: asking (INCOMPLETE)
-
hub1 repeats it out of every other port
A hub does not read addresses. It copies the signal out of every other port (2, 3, 4), so every device sees this frame.
- Time
- 100.512 µs
- Cable
- hub1 2 → laptop-b eth0 (+2 more)
- Ethernet
- 02:00:00:00:00:0a → ff:ff:ff:ff:ff:ff (broadcast)
- ARP
- who has 192.168.1.11? tell 192.168.1.10
- On the wire
- 64 bytes
-
laptop-b: ARP: 192.168.1.11 is at 02:00:00:00:00:0b
laptop-b answers only the one who asked: 192.168.1.11 is at 02:00:00:00:00:0b. laptop-b saves it in its ARP cache: 192.168.1.10 is at 02:00:00:00:00:0a.
- Time
- 201.024 µs
- Cable
- laptop-b eth0 → hub1 2
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- ARP
- 192.168.1.11 is at 02:00:00:00:00:0b
- On the wire
- 64 bytes
- laptop-b ARP cache
- 192.168.1.10 is at 02:00:00:00:00:0a
-
hub1 repeats it out of every other port
A hub does not read addresses. It copies the signal out of every other port (1, 3, 4), so every device sees this frame.
- Time
- 301.536 µs
- Cable
- hub1 1 → laptop-a eth0 (+2 more)
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- ARP
- 192.168.1.11 is at 02:00:00:00:00:0b
- On the wire
- 64 bytes
-
laptop-a: ICMP echo request seq=1 192.168.1.10 → 192.168.1.11
laptop-a sends an ICMP echo request ("are you there?") to 192.168.1.11, in a frame addressed to laptop-b. laptop-a saves it in its ARP cache: 192.168.1.11 is at 02:00:00:00:00:0b.
- Time
- 402.048 µs
- Cable
- laptop-a eth0 → hub1 1
- Ethernet
- 02:00:00:00:00:0a → 02:00:00:00:00:0b
- IP
- 192.168.1.10 → 192.168.1.11
- TTL
- 64
- ICMP
- echo request, seq 1
- On the wire
- 102 bytes
- laptop-a ARP cache
- 192.168.1.11 is at 02:00:00:00:00:0b
-
hub1 repeats it out of every other port
A hub does not read addresses. It copies the signal out of every other port (2, 3, 4), so every device sees this frame.
- Time
- 502.864 µs
- Cable
- hub1 2 → laptop-b eth0 (+2 more)
- Ethernet
- 02:00:00:00:00:0a → 02:00:00:00:00:0b
- IP
- 192.168.1.10 → 192.168.1.11
- TTL
- 64
- ICMP
- echo request, seq 1
- On the wire
- 102 bytes
-
laptop-b: ICMP echo reply seq=1 192.168.1.11 → 192.168.1.10
laptop-b answers with an echo reply.
- Time
- 603.68 µs
- Cable
- laptop-b eth0 → hub1 2
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- IP
- 192.168.1.11 → 192.168.1.10
- TTL
- 64
- ICMP
- echo reply, seq 1
- On the wire
- 102 bytes
-
hub1 repeats it out of every other port
A hub does not read addresses. It copies the signal out of every other port (1, 3, 4), so every device sees this frame.
- Time
- 704.496 µs
- Cable
- hub1 1 → laptop-a eth0 (+2 more)
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- IP
- 192.168.1.11 → 192.168.1.10
- TTL
- 64
- ICMP
- echo reply, seq 1
- On the wire
- 102 bytes
-
laptop-a receives ICMP echo reply seq=1 192.168.1.11 → 192.168.1.10
laptop-a gets the frame. The reply arrived 0.805 ms after the request left: that is the round-trip time. laptop-a prints: rtt min/avg/max/mdev = 0.805/0.805/0.805/0.000 ms
- Time
- 805.312 µs
- Ethernet
- 02:00:00:00:00:0b → 02:00:00:00:00:0a
- IP
- 192.168.1.11 → 192.168.1.10
- TTL
- 64
- ICMP
- echo reply, seq 1
- On the wire
- 102 bytes
-
laptop-c: tcpdump shows what it saw
laptop-c prints: 4 packets captured
- Time
- 1.805 ms
laptop-c saw all four frames. Its network card ignored the three that were not for it, but a program like tcpdump can ask the card to keep everything. On a hub, anyone can read everyone’s traffic. On a switch, a device mostly sees broadcasts and its own frames. That is better for privacy and much better for speed: two pairs of laptops can talk at the same time through a switch without getting in each other’s way.
In the real world
Real switches forget an entry if they have not heard from that MAC address for a while (often 5 minutes), so a laptop that moves to another port is soon found again. Hubs have vanished from shops. Wi-Fi, though, behaves partly like a hub: every device in range can receive every frame over the air. That is one reason Wi-Fi is encrypted (Lesson 2.4).
Recap
- A switch learns from the source MAC of every frame which port each device is on.
- It forwards frames to a known destination on one port only, and floods broadcasts and unknown destinations.
- The table starts empty and fills itself; nobody configures it.
- A hub repeats every frame to every port, so every device can see all traffic.
Quick check
-
Learning uses the source address; the destination is only looked up.
-
Flooding makes sure the unknown receiver gets it. Its answer then teaches the switch where it is.
-
On a hub every device gets every frame. On a switch, devices mostly see broadcasts and their own traffic.
Join the discussion