You type ping 192.168.1.11. Your laptop now has an IP address to send to. But in Lesson 2.1 you saw that every frame on the cable needs a destination MAC address. Nobody told your laptop laptop-b’s MAC address. Where does it come from?
It asks. The protocol that does the asking is ARP, the Address Resolution Protocol, and it is the reason the first ping in Lesson 1.4 was twice as slow as the others.
Ask everyone, get one answer
ARP is one question and one answer:
- Request, sent as a broadcast so everyone gets it: “Who has 192.168.1.11? Tell 192.168.1.10.” It includes the asker’s own MAC address.
- Reply, sent only to the asker: “192.168.1.11 is at 02:00:00:00:00:0b.”
The asker saves the answer in its ARP cache, a small table of IP addresses and their MAC addresses, so it does not have to ask again for a while. Watch it with two pings in a row, then ip neigh (short for “neighbours”), which shows the cache.
The first ping needs ARP, the second does not
-
laptop-a: ping -c 2 192.168.1.11
laptop-a's ARP cache has no entry for 192.168.1.11, so the ping has to wait. laptop-a broadcasts the question. Open the Bytes view to see the request: the target MAC is all zeros, because that is what it is asking for.
- 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 saves the answer and finally sends the ping that was waiting.
- 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: 64 bytes from 192.168.1.11: icmp_seq=1 ttl=64 time=0.805 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-a: ICMP echo request seq=2 192.168.1.10 → 192.168.1.11
The second ping goes out at once: the answer is in the cache.
- Time
- 1 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 2
- On the wire
- 102 bytes
-
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
- 1 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 2
- On the wire
- 102 bytes
-
laptop-b: ICMP echo reply seq=2 192.168.1.11 → 192.168.1.10
laptop-b answers with an echo reply.
- Time
- 1 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 2
- 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
- 1 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 2
- On the wire
- 102 bytes
-
laptop-a receives ICMP echo reply seq=2 192.168.1.11 → 192.168.1.10
laptop-a gets the frame. The reply arrived 0.403 ms after the request left: that is the round-trip time. laptop-a prints: rtt min/avg/max/mdev = 0.403/0.604/0.805/0.201 ms
- Time
- 1 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 2
- On the wire
- 102 bytes
-
laptop-a: ip neigh
laptop-a runs ip neigh.
- Time
- 1 s
Look at step 3 again. laptop-b did something clever: the question already contained laptop-a’s IP and MAC addresses, so laptop-b saved them straight away. When it sends its echo reply, it does not need to ask anything.
laptop-c and laptop-d also got the question, but saved nothing: it was not about them.
The capture check behind this lab ran the same pings on real Linux computers. Both laptops’ recordings showed exactly one ARP request and one reply, then the two pings and their replies.
The ARP cache
ip neigh printed one line:
192.168.1.11 dev eth0 lladdr 02:00:00:00:00:0b REACHABLE
lladdr is the “link-layer address”, the MAC. REACHABLE means the entry was confirmed very recently. Entries do not last forever. After a short while without traffic Linux marks them STALE, and checks again before trusting them, because devices leave and addresses get reused. An entry that never got an answer shows as FAILED, as when you pinged an address nobody had in Lesson 1.4.
Who do you ARP for?
A laptop only ARPs for addresses on its own network. To reach anything else (a website, say), it ARPs for its default gateway, the router, and hands the packet to it. You saw exactly that at the very start of Lesson 1.1: the first message of the whole journey was an ARP for the home router. You will see how a laptop decides “mine or not mine” in Lesson 3.2.
In the real world: when ARP is lied to
ARP has no proof of identity. Any device on the network can send a reply saying “192.168.1.1 is at my MAC address”, and devices that believe it will send their traffic for the router to it instead. This is called ARP spoofing, and it is why sharing a network with strangers (a café’s Wi-Fi, a hotel’s cable) carries risk.
Networks defend against it in two ways. Managed switches in offices can check ARP messages against a list of which address belongs to which port (often called dynamic ARP inspection) and drop the lies. And encryption, which you will meet in Module 7, makes the risk much smaller: if your traffic is encrypted with HTTPS, a device that receives it by tricking ARP can see where it goes, but cannot read or change it without being noticed.
Recap
- ARP finds the MAC address that goes with an IP address on the local network.
- The request is a broadcast; only the owner replies, directly to the asker.
- Answers are kept in the ARP cache (
ip neigh), so later packets go out at once. - The first packet to a new neighbour waits for ARP, so the first ping is slower.
- A laptop ARPs for local addresses directly, and for its gateway to reach everything else.
Quick check
-
If it knew which card to send to, it would not need to ask.
-
It saves asking again for every packet.
-
The time ping prints for the first reply includes that extra round trip.
Join the discussion