5 · ARP and bridges
In one sentence: on a link, packets are delivered to MAC addresses; ARP finds the MAC that has an IP address by asking everyone on the link, and a bridge is a virtual switch that joins many cables into one link and learns which port each MAC is behind.
The problem it solves
Lesson 3’s route said “10.0.0.0/24 is on veth-red’s link: send directly”. But a frame on a link is addressed to a
MAC address (the hardware address from lesson 2), not to an IP address. Red knows 10.0.0.2; it doesn’t know
which MAC that is. And a veth pair joins exactly two machines; a real network has a dozen on the same link.
Two pieces solve both: ARP answers “which MAC has this IP?”, and a switch lets many machines share one link.
ARP: shout the question, get a private answer
Red asks the whole link: “who has 10.0.0.2? tell 10.0.0.1”. The request goes to the broadcast MAC
ff:ff:ff:ff:ff:ff, which every machine on the link receives. Only the owner answers, straight to red. Here is
red’s first ping to blue, seen from blue (tcpdump -e adds the MACs; timestamps cut):
9e:5f:c1:50:6d:6b > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.0.0.2 tell 10.0.0.1, length 28
7e:ef:d2:7a:28:8d > 9e:5f:c1:50:6d:6b, ethertype ARP (0x0806), length 42: Reply 10.0.0.2 is-at 7e:ef:d2:7a:28:8d, length 28
9e:5f:c1:50:6d:6b > 7e:ef:d2:7a:28:8d, ethertype IPv4 (0x0800), length 98: 10.0.0.1 > 10.0.0.2: ICMP echo request, id 2737, seq 1, length 64
Read the left of each line: request to everyone, reply to red, then the ping itself, from red’s MAC to blue’s.
Red stores the answer in its neighbour table (ip neigh), so the next packets skip the question. The entry is
REACHABLE for about 30 seconds, then STALE: still used, but checked again the next time it’s needed.
When nobody answers
Ping an address on the link that no machine has, 10.0.0.9. Red asks three times, a second apart, then gives up:
the neighbour entry becomes FAILED, and the error comes from red itself:
From 10.0.0.1 icmp_seq=1 Destination Host Unreachable
A TCP connection to it fails after about 3 seconds with the message lesson 1 left unexplained:
nc: connect to 10.0.0.9 port 8080 (tcp) failed: No route to host
The name misleads: the route was fine (10.0.0.0/24 is on the link); a missing route is Network is unreachable (lesson 3), and it’s instant. “No route to host” after about 3 seconds
means nobody on the link answered ARP: the machine is off, unplugged, or doesn’t have that address. (The same
words at once come from a firewall rule that rejects with “host prohibited”: lesson 7.)
A bridge: a switch inside the kernel
A bridge is a virtual switch: an interface whose ports are other interfaces. A frame that comes in on one
port goes out of the port where its destination MAC is. The lab’s version puts the switch in its own namespace,
switch, with one veth cable to each machine:
red 10.0.0.1 blue 10.0.0.2 green 10.0.0.3
veth-red veth-blue veth-green
| | |
switch: sw-red ------------- sw-blue -------------- sw-green
\___________________ br0 ___________________/
ip netns add switch
ip -n switch link add br0 type bridge
ip -n switch link set br0 up
ip -n switch link set sw-red master br0
master br0 plugs a port into the switch. bridge -n switch link lists the ports:
3: sw-red@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 2
5: sw-blue@if6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 2
7: sw-green@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 2
The bridge needs no IP address; red, blue and green have the addresses, all in 10.0.0.0/24, one link.
The switch learns
Each frame that comes in on a port tells the bridge “this MAC is behind this port”. It keeps that in its
forwarding database, bridge -n switch fdb show br br0 (the entries without permanent are the learned ones):
9e:5f:c1:50:6d:6b dev sw-red master br0
7e:ef:d2:7a:28:8d dev sw-blue master br0
6e:fd:8f:a0:41:5f dev sw-green master br0
A broadcast goes out of every port; a frame to a known MAC goes out of one. tcpdump in green during red’s
first ping to blue catches exactly one frame of it, the ARP request:
15:42:09.971304 9e:5f:c1:50:6d:6b > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 10.0.0.2 tell 10.0.0.1, length 28
The reply and the pings went only to the ports of red and blue. (Green’s tcpdump also shows a few IPv6
“router solicitation” frames that new interfaces send by themselves; Practical 2 filters them out with
arp or icmp.)
Unplugged from the switch
ip -n switch link set sw-green nomaster takes green’s port out of the bridge. Green’s own interface still says
UP and LOWER_UP: its cable is plugged in at both ends, into a switch port that leads nowhere. After
ip -n red neigh flush all (red forgets green’s MAC), red’s ping to 10.0.0.3 gets 100% packet loss and the
neighbour entry turns FAILED.
LOWER_UP says the cable is there, not that the switch passes it: bridge link is where the missing port shows.
| What you see | It means | Look at |
|---|---|---|
neighbour REACHABLE / STALE | ARP worked | |
neighbour FAILED, Destination Host Unreachable from yourself | nobody answered ARP | the far machine’s address and link, the switch ports |
No route to host after about 3 s | the same, seen by TCP | same |
Try it on your computer
Practical 2, after lesson 6, builds this switch with three machines on it and puts a service on blue.
Go deeper: docker0 is this bridge
Lesson 2 found your lab container’s other veth end on the host, master docker0. Read docker0 on your server
(read-only, no sudo):
ip -d link show docker0
ip -br link show master docker0
bridge forward_delay 1500 hello_time 200 max_age 2000 ageing_time 30000 stp_state 0 ...
vethbc0bbc6@if2 UP 4e:17:e1:f8:8f:1a <BROADCAST,MULTICAST,UP,LOWER_UP>
A bridge with one port per container; @if2 is, as in lesson 2, the index of the partner, the container’s end. docker0’s own MAC is ea:92:21:b2:12:84, the same MAC lesson 2’s container
had in its neighbour table for its gateway 172.17.0.1. Unlike the lab’s br0, docker0 has an address
(172.17.0.1): the bridge itself is the containers’ gateway, the host’s way into that network. More in
ip-link(8), “bridge”.
Go deeper: the neighbour table's timers
Three settings per interface explain the numbers above (arp(7)):
net.ipv4.neigh.veth-red.base_reachable_time_ms = 30000
net.ipv4.neigh.veth-red.mcast_solicit = 3
net.ipv4.neigh.veth-red.retrans_time_ms = 1000
An answer keeps an entry REACHABLE for a random time between 15 and 45 seconds (half to one and a half times
30). Then it’s STALE; when it’s next used, the kernel checks it again with a unicast ARP, straight to the
MAC it already has. An unanswered address gets 3 broadcast requests, 1 second apart: 3 × 1 s.
Common misunderstandings
- “
Destination Host Unreachablecame from the far machine.” Look at theFrom:10.0.0.1, red itself. Red couldn’t find a MAC for the address. - “Every machine on a switch sees all the traffic.” Only broadcasts (and multicasts), and frames to MACs the switch hasn’t learned yet. Green saw red’s ARP request and none of the pings.
Check yourself
1. ip neigh in red shows 10.0.0.3 dev veth-red FAILED, and green's ip -br link says UP with LOWER_UP. Where do you look next?
At the switch: bridge -n switch link. If sw-green isn't listed, its port is out of the
bridge (ip -n switch link set sw-green master br0 puts it back). Also check that green really has
10.0.0.3.
2. A curl to a server on your network fails after about 3 seconds with "No route to host", but ip route get shows a route. What happened?
ARP got no answer: three requests a second apart. The server is down, unplugged, or not using that address.
3. You run tcpdump on green and want to see red's pings to blue. Will you?
No: after the first ARP request (a broadcast), the bridge sends red's and blue's frames only to each other's
ports. Run it on blue, or on the switch's sw-blue port.