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 | |
|---|---|---|
| Input | api.kade.lk | 172.16.1.20 |
| Output | 34.87.120.15 | 30:05:5c:8a:12:e0 |
| Who answers | A chain of DNS servers | The device that owns the IP |
| Reach | The whole internet | Only the local network |
| Result kept for | The record's TTL | Seconds 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:
| Device | IP | MAC |
|---|---|---|
| Front desk PC | 172.16.1.10 | 3c:7c:3f:10:22:01 |
| Manager laptop | 172.16.1.11 | f0:18:98:6d:2e:44 |
| Office printer | 172.16.1.20 | 30:05:5c:8a:12:e0 |
| Router, eth1 (gateway) | 172.16.1.1 | e4:8d:8c:00:01:01 |
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
Wide by design - scroll it sideways.
- 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." - 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.
- 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
toff:ff:ff:ff:ff:ffeveryone
from3c:7c:3f:10:22:01the PC
- 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.
2 · Reply · unicast: only the PC gets it
to3c:7c:3f:10:22:01only the PC
from30:05:5c:8a:12:e0the printer
- 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.
- the frame (chapter 1, wrap 3)
- request
- reply
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
learned earlier, when the PC first went online
After
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:
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 MAC | e4:8d:8c:00:01:01 | router eth1, from ARP |
| Destination IP | 34.87.120.15 | kade-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.
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
| # | Idea | In one line | New terms |
|---|---|---|---|
| 1 | Job | IP in, MAC out, local network only | ARP |
| 2 | Before ARP | Mask check decides whose IP to ask for: target or gateway | |
| 3 | Request / reply | Broadcast "who has X?"; only the owner replies, unicast | ARP request, ARP reply |
| 4 | Message | Sender MAC/IP, target MAC/IP; request's target MAC is all zeros | |
| 5 | Cache | IP → MAC table; entries expire; the target learns the sender too | ARP table |
| 6 | Other networks | ARP for the gateway's IP; never for a far-away target | |
| 8 | Security | No checks, so replies can be faked | ARP 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 -aDelete one entry
- What to look for: Run
arp -aafter 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.1Live ARP traffic
- What to look for:
Request who-has 192.168.1.1 tell 192.168.1.23and theReply … is-at …after it. - Runs on: macOS (Linux: -i wlan0 or eth0)
- From section: 3. Request and reply
sudo tcpdump -n -i en0 arpSend 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