Chapters

ARP: from IP to MAC

A device always knows the IP it wants to reach, but the frame needs a MAC. ARP fills that gap. It is one of the simplest protocols in networking, and it runs before almost every conversation on a local network.

Addressing and local delivery · chapter 9 of 34 · 5 min read

What ARP does

ARP (Address Resolution Protocol) has one job: give it an IP address on your local network, and it returns the MAC address of the interface that holds that IP.

You already know a lookup like this. DNS turns a name into an IP. ARP turns an IP into a MAC:

DNS (chapter 1)ARP
Inputapi.kade.lk172.16.1.20
Output34.87.120.1530:05:5c:8a:12:e0
Who answersA chain of DNS serversThe device that owns the IP
ReachThe whole internetOnly the local network
Result kept forThe record's TTLSeconds to minutes (depends on the OS)

The setup: the office staff network

We use the staff network from chapter 6. Every device now has its MAC listed:

DeviceIPMAC
Front desk PC172.16.1.103c:7c:3f:10:22:01
Manager laptop172.16.1.11f0:18:98:6d:2e:44
Office printer172.16.1.2030:05:5c:8a:12:e0
Router, eth1 (gateway)172.16.1.1e4:8d:8c:00:01:01
All use mask 255.255.255.0. The front desk PC wants to print an order on the office printer.

The PC already knows the printer's IP (the print setup stores it, just as your frontend knows the backend's address after DNS). First, the mask check from chapter 4: 172.16.1.10 AND mask = 172.16.1.0, and 172.16.1.20 AND mask = 172.16.1.0. Same network, so the PC can deliver directly. But to build the frame, it needs the printer's MAC.

Request and reply

Front desk PC172.16.1.103c:7c:3f:10:22:01Manager laptop172.16.1.11 · not me, ignoreOffice printer172.16.1.20 · that's meRouter eth1172.16.1.1 · not me, ignore1 · broadcast to ff:ff:ff:ff:ff:ff (everyone)"who has 172.16.1.20? tell 172.16.1.10"2 · reply, only to the PC"172.16.1.20 is at 30:05:5c:8a:12:e0"

Wide by design - scroll it sideways.

  1. Request, sent as a broadcast. The PC sends a frame to ff:ff:ff:ff:ff:ff, the broadcast MAC (chapter 7). The switch copies it to every port, so every device on the network gets it. It asks: "Who has 172.16.1.20? Tell 172.16.1.10."
  2. Everyone checks. Each device compares 172.16.1.20 with its own IP. The manager laptop and the router do not match, so they ignore it.
  3. Only the owner replies, and only to the PC. The printer sends "172.16.1.20 is at 30:05:5c:8a:12:e0" straight back to the PC's MAC. The reply is unicast, not a broadcast.

What is inside an ARP message

Both messages carry the same four address fields: a sender MAC and IP, and a target MAC and IP. Only the values change:

1 · Request · broadcast: every device on the network gets it

Ethernet header

toff:ff:ff:ff:ff:ffeveryone

from3c:7c:3f:10:22:01the PC

no IP header
ARP message · operation 1, request
sender
MAC3c:7c:3f:10:22:01
IP172.16.1.10
target
MAC00:00:00:00:00:00
IP172.16.1.20

target MAC: unknown: this is the question.

FCS

2 · Reply · unicast: only the PC gets it

Ethernet header

to3c:7c:3f:10:22:01only the PC

from30:05:5c:8a:12:e0the printer

no IP header
ARP message · operation 2, reply
sender
MAC30:05:5c:8a:12:e0
IP172.16.1.20
target
MAC3c:7c:3f:10:22:01
IP172.16.1.10

sender MAC: the answer. Sender and target have swapped: the printer speaks now.

FCS
  • the frame (chapter 1, wrap 3)
  • request
  • reply
ARP is carried directly in a frame. There is no IP packet around it, which is why it can work before a device knows anyone's MAC.

The ARP table (cache)

Broadcasting before every single frame would waste the whole network's time. So every device keeps an ARP table: a small cache of IP → MAC pairs it has learned. The PC's table before and after:

Before

172.16.1.1 → e4:8d:8c:00:01:01

learned earlier, when the PC first went online

After

172.16.1.1 → e4:8d:8c:00:01:01
172.16.1.20 → 30:05:5c:8a:12:e0

the next print job skips the broadcast

  • Entries expire. After a while (seconds to minutes, depending on the OS) an unused entry is dropped or rechecked. If the printer is replaced, its new MAC is picked up on the next lookup.
  • The target learns too. The request already contained the PC's IP and MAC, so the printer saves 172.16.1.10 → 3c:7c:3f:10:22:01. When it replies, it does not need to ask.
  • A small correction to the notes: a device does not find its own MAC in the ARP table. It knows its own addresses from its interface settings. The table holds other devices.

When the target is on another network

Now the PC loads an order from kade-api (34.87.120.15). The mask check fails: 34.87.120.0 is not 172.16.1.0. So the PC must send to its default gateway, 172.16.1.1 (it got that from DHCP, chapter 5). It runs ARP for the gateway's IP, and this time the router replies:

Front desk PC172.16.1.103c:7c:3f:10:22:01Manager laptop172.16.1.11 · not me, ignoreOffice printer172.16.1.20 · not me, ignoreRouter eth1172.16.1.1 · that's me1 · broadcast to ff:ff:ff:ff:ff:ff (everyone)"who has 172.16.1.1? tell 172.16.1.10"2 · reply, only to the PC"172.16.1.1 is at e4:8d:8c:00:01:01"

Wide by design - scroll it sideways.

The frame then goes out with the router's MAC and kade-api's IP, just as in chapters 1 and 5:

Destination MACe4:8d:8c:00:01:01router eth1, from ARP
Destination IP34.87.120.15kade-api, unchanged

Try it: an ARP simulator

Pick a sender and a target, then press Send. The first time, you will see a broadcast. Press Send again and the cache answers instead. The cache stays until you clear it.

Sender
Target

Press Send to start. All ARP caches start empty.

ARP trusts everyone

ARP has no checks. Any device can send a reply, even one nobody asked for, and most devices will cache it. An attacker on the staff network could send "172.16.1.1 is at my MAC". The PC would then send all its internet traffic to the attacker first. This is called ARP spoofing, and it is one reason public WiFi is risky and why HTTPS (TLS) matters even on a "private" network. Managed switches can block it with a feature called dynamic ARP inspection.

Summary

#IdeaIn one lineNew terms
1JobIP in, MAC out, local network onlyARP
2Before ARPMask check decides whose IP to ask for: target or gateway
3Request / replyBroadcast "who has X?"; only the owner replies, unicastARP request, ARP reply
4MessageSender MAC/IP, target MAC/IP; request's target MAC is all zeros
5CacheIP → MAC table; entries expire; the target learns the sender tooARP table
6Other networksARP for the gateway's IP; never for a far-away target
8SecurityNo checks, so replies can be fakedARP spoofing

Try it yourself

Your ARP table

  • What to look for: Your gateway's IP with its MAC. Browse a bit, print something, run it again: new entries appear.
  • Runs on: macOS / Linux / Windows · Linux also: ip neigh
  • From section: 5. The ARP table (cache)
arp -a

Delete one entry

  • What to look for: Run arp -a after loading any page: the gateway is back, learned again by a broadcast.
  • Runs on: macOS / Linux · Windows (admin): arp -d
  • From section: 5. The ARP table (cache)
sudo arp -d 192.168.1.1

Live ARP traffic

  • What to look for: Request who-has 192.168.1.1 tell 192.168.1.23 and the Reply … is-at … after it.
  • Runs on: macOS (Linux: -i wlan0 or eth0)
  • From section: 3. Request and reply
sudo tcpdump -n -i en0 arp

Send ARP requests by hand

  • What to look for: Each reply shows the gateway's MAC.
  • Runs on: Linux (install arping)
  • From section: 3. Request and reply
arping -c 3 192.168.1.1

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