3. ARP: From IP to MAC

How a host finds out who is behind an IP address on its own network

You arrive at a busy party with a parcel for someone called Alex. You know the name, but you have no idea which of the forty faces in the room is Alex. So you climb onto a chair and call out: "Who's Alex? It's Sam, by the door!" Everyone hears it. Thirty-nine people shrug and carry on talking. One person walks over: "That's me." Now you know Alex's face, and you hand over the parcel. As a bonus, Alex now knows who Sam is, without having to ask. And the next time you have something for Alex, you won't need to shout at all: you'll remember.

That is the Address Resolution Protocol, ARP, almost exactly. In the Ethernet article we saw that every frame needs a destination MAC address, and in the Layers article our laptop sent a frame to the router at 02:00:00:cc:dd:02. But the laptop was only ever told the router's IP address, 192.168.1.1. Somewhere between "I want to reach 192.168.1.1" and "put 02:00:00:cc:dd:02 in the frame header", the laptop shouted a question to the whole network. This article is about that shout.

The Gap Between Two Layers

Think about what each layer knows when the laptop wants to send a packet:

  • IP knows where. The packet's destination is 192.168.1.1 (or a web server across the world). IP addresses are assigned by configuration: typed in by hand, or handed out by a DHCP server. They describe a position in a network, like a postal address.
  • Ethernet needs who on this wire. A frame can only be delivered to an interface identified by its 48-bit MAC address. MAC addresses come from the hardware (or from the operating system, if randomized) and say nothing about where the device sits.

There is no formula that turns one into the other. 192.168.1.1 could be a router with any MAC address at all, and if you swap the router for a new one tomorrow, the IP stays the same while the MAC changes. So the mapping has to be discovered, at run time, by asking. ARP was designed for exactly this in RFC 826 (1982), and it has barely changed since.

Here's the home network we've been using throughout this series, now with every device's IP address filled in. All four sit on the same switch, in the 192.168.1.0/24 network (every address from 192.168.1.0 to 192.168.1.255):

Device IP address MAC address
Laptop 192.168.1.10 02:00:00:aa:bb:01
Printer 192.168.1.20 02:00:00:aa:bb:03
NAS 192.168.1.30 02:00:00:aa:bb:04
Router (default gateway) 192.168.1.1 02:00:00:cc:dd:02

Beyond the router lies the Internet, including the web server at 203.0.113.80 that our laptop was talking to in the Layers article.

Is ARP Layer 2 or Layer 3?

Neither, quite. ARP messages ride directly inside Ethernet frames (no IP header at all), but their whole purpose is to serve IP. People sometimes call it "Layer 2.5". The label matters less than the job: ARP is the glue between an IP address and the link-layer address that can actually carry the frame.

Ask the Room: Request and Reply

The laptop has an IP packet for 192.168.1.1 and no idea what MAC address to use. Here's the full exchange:

Laptop .10 · …aa:bb:01 Printer .20 · …aa:bb:03 NAS .30 · …aa:bb:04 Router .1 · …cc:dd:02 1. Request, broadcast to ff:ff:ff:ff:ff:ff "Who has 192.168.1.1? Tell 192.168.1.10 (02:00:00:aa:bb:01)" not me: ignore not me: ignore that's me! caches .10 → …aa:bb:01 2. Reply, unicast to 02:00:00:aa:bb:01 "192.168.1.1 is at 02:00:00:cc:dd:02" never sees it never sees it caches .1 → …cc:dd:02 3. The original IP packet, sent to 02:00:00:cc:dd:02 Next time, both sides skip steps 1 and 2: the answer is in their caches.
  1. The laptop checks its cache

    Every host keeps an ARP cache: a small table of recently learned IP → MAC pairs. There's no entry for 192.168.1.1, so the laptop holds the IP packet in a queue and asks.

  2. Request: a broadcast "who-has"

    The laptop builds an ARP request and sends it to the broadcast MAC ff:ff:ff:ff:ff:ff. As the Ethernet article explained, a switch floods broadcasts out of every port, so the printer, the NAS and the router all receive it. The request says, in effect: "I'm 192.168.1.10 at 02:00:00:aa:bb:01. Whoever has 192.168.1.1, please tell me your MAC."

  3. Everyone else ignores it

    The printer and NAS read the target IP, see it isn't theirs, and do nothing (with one small exception we'll meet below). They still had to wake up and look, though: that's the cost of a broadcast.

  4. Reply: a unicast "is-at"

    The router recognises its own address. It writes the laptop's details into its own cache, then sends an ARP reply directly to 02:00:00:aa:bb:01: "192.168.1.1 is at 02:00:00:cc:dd:02." No broadcast is needed, because the request told it exactly who was asking.

  5. The laptop caches the answer and sends

    The laptop stores 192.168.1.1 → 02:00:00:cc:dd:02, takes the waiting IP packet out of the queue, wraps it in an Ethernet frame addressed to the router, and sends it. That's the 95-byte frame we took apart in the Layers article.

If you capture this with tcpdump on the laptop, the whole thing is two lines:

ARP, Request who-has 192.168.1.1 tell 192.168.1.10, length 28
ARP, Reply 192.168.1.1 is-at 02:00:00:cc:dd:02, length 46

Wireshark phrases it as "Who has 192.168.1.1? Tell 192.168.1.10" and "192.168.1.1 is at 02:00:00:cc:dd:02". The request's "length 28" is the size of the ARP message itself. The reply says 46 because it arrived with Ethernet padding attached; we'll see why in a moment.

The asker gets learned for free

Notice what happened at step 4. The router hadn't asked anything, yet it ended up knowing the laptop's MAC. That's deliberate. RFC 826 observes that if A is asking for B, then B is very likely about to send something back to A, so B should learn A's address from the request instead of broadcasting a request of its own a moment later. One round trip, and both sides know each other. (Linux files an entry learned this way as STALE rather than fully confirmed, so it gets re-checked the first time it's used; more on cache states below.)

The RFC spells out the receive logic precisely, and it has one more subtlety:

RFC 826's merge rule

First, refresh what you already know. If the sender's IP is already in my cache, overwrite its MAC with the one in this packet, whoever the packet is for.

Then, only if I'm the target, learn something new. If the target IP is mine and the sender wasn't in my cache, add it. If it was a request, send a reply.

That's the "small exception" from step 3. If the printer already had an entry for 192.168.1.10 (because it printed something for the laptop last week), it updates that entry from the broadcast, even though the request wasn't for it. But if it had no entry, it doesn't create one. This keeps caches fresh without filling every host's table with every machine that ever broadcast a request. Hold on to this rule: it's why gratuitous ARP works, and also why ARP spoofing does.

Here is the reception algorithm as pseudocode, closely following the RFC:

function on_arp_packet(pkt, iface):
    if pkt.htype != 1 or pkt.ptype != 0x0800:    # not Ethernet + IPv4: not for us
        drop
    merged = false
    if pkt.spa in cache:                         # 1. refresh what we already knew
        cache[pkt.spa] = pkt.sha
        merged = true
    if pkt.tpa == iface.ip:                      # 2. is this about me?
        if not merged:
            cache[pkt.spa] = pkt.sha             #    learn the asker for free
        if pkt.oper == REQUEST:
            reply = arp(oper = REPLY,
                        sha = iface.mac, spa = iface.ip,
                        tha = pkt.sha,   tpa = pkt.spa)
            send_frame(dst = pkt.sha, src = iface.mac,
                       ethertype = 0x0806, payload = reply)

(The abbreviations are the packet's field names: SHA and SPA are the sender's hardware and protocol addresses, THA and TPA the target's. We'll see them on the wire next.)

And the sending side, which is where the queue and the retries live:

function resolve(next_hop_ip, packet):
    entry = cache.get(next_hop_ip)
    if entry is usable:
        return entry.mac
    queue(packet, waiting_for = next_hop_ip)
    repeat up to 3 times, 1 second apart:        # Linux defaults; other OSes differ
        broadcast arp(oper = REQUEST,
                      sha = my_mac, spa = my_ip,
                      tha = 00:00:00:00:00:00,   # unknown: that's the question
                      tpa = next_hop_ip)
        if a reply arrives:
            send everything queued for next_hop_ip
            return
    mark next_hop_ip FAILED
    drop the queue; report "host unreachable"

That last line is what you see when you ping an address nobody is using on your own network: after a few seconds of silence, your own machine replies "Destination Host Unreachable". No router said that. Your laptop gave up on ARP.

The ARP Packet

An ARP message is tiny and has a fixed layout. Inside an Ethernet frame it's marked with EtherType 0x0806 (where IPv4 is 0x0800), and it looks like this, drawn four bytes per row in the style of the RFCs, with the values from the laptop's request:

ARP message for Ethernet + IPv4: 28 bytes byte 0 byte 1 byte 2 byte 3 0 4 8 12 16 20 24 Hardware type (HTYPE) 00 01 = Ethernet Protocol type (PTYPE) 08 00 = IPv4 HLEN 06 PLEN 04 Operation (OPER) 00 01 = request (2 = reply) Sender hardware address (SHA), bytes 0–3 02 00 00 aa SHA, bytes 4–5 bb 01 Sender IP (SPA), bytes 0–1 c0 a8 SPA, bytes 2–3 01 0a Target hardware address (THA), 0–1 00 00 THA, bytes 2–5 00 00 00 00 Target IP (TPA) c0 a8 01 01 = 192.168.1.1 The addresses don't line up with the 4-byte rows: 6-byte MACs and 4-byte IPs interleave.
Offset Field (bytes) Request Reply
0 HTYPE (2) 00 01 00 01
2 PTYPE (2) 08 00 08 00
4 HLEN (1) 06 06
5 PLEN (1) 04 04
6 OPER (2) 00 01 00 02
8 SHA (6) laptop MAC router MAC
14 SPA (4) 192.168.1.10 192.168.1.1
18 THA (6) all zeros laptop MAC
24 TPA (4) 192.168.1.1 192.168.1.10

HTYPE 1 means Ethernet; PTYPE 0800 means IPv4 (the same number as its EtherType); HLEN and PLEN are the address lengths, 6 and 4 bytes; OPER is 1 for a request and 2 for a reply. SHA/SPA are the sender's MAC and IP, THA/TPA the target's. In a request THA is unknown, so it's left as zeros.

Two things stand out.

ARP isn't really about IP. The hardware and protocol types are parameters, and the two length fields tell a receiver how big the addresses are. Plummer designed ARP in 1982 to resolve any protocol's addresses over any hardware, and the RFC mentions protocols like Xerox PUP and Chaosnet alongside IP. In practice today it's almost always 1 / 0x0800 / 6 / 4, which is why the message is always 28 bytes: 8 bytes of fixed header plus 6 + 4 + 6 + 4 bytes of addresses. (Wi-Fi uses the same hardware type 1, because Wi-Fi interfaces have Ethernet-style 48-bit MACs.)

The sender's addresses are in the message, not just the frame. The Ethernet header already has a source MAC, so SHA looks redundant. It isn't: the ARP module may not get to see the Ethernet header, and some setups (like the proxy ARP we'll meet later) send ARP messages whose frame source differs from the sender being described. ARP trusts SHA, not the frame header.

The whole frame, request and reply

28 bytes of ARP plus a 14-byte Ethernet header is 42 bytes, too short for Ethernet's 46-byte minimum payload. So, exactly as the Ethernet article promised, 18 bytes of zero padding go after the ARP message, then the 4-byte FCS: 14 + 28 + 18 + 4 = 64 bytes, the minimum frame. Here is the laptop's request, byte for byte, with the FCS computed for these exact bytes:

ARP request: 64 bytes

0000  ff ff ff ff ff ff 02 00 00 aa bb 01 08 06 00 01
0010  08 00 06 04 00 01 02 00 00 aa bb 01 c0 a8 01 0a
0020  00 00 00 00 00 00 c0 a8 01 01 00 00 00 00 00 00
0030  00 00 00 00 00 00 00 00 00 00 00 00 cc 12 a5 e1

 Ethernet header  bytes 0–13 ·  ARP  bytes 14–41 ·  Padding  bytes 42–59 ·  FCS  bytes 60‑63

Reading it the way a receiver would:

  1. Offset 0x00: Ethernet header

    Destination ff:ff:ff:ff:ff:ff, broadcast. Source 02:00:00:aa:bb:01, the laptop. EtherType 08 06: ARP.

  2. Offset 0x0e: ARP fixed header

    00 01 Ethernet, 08 00 IPv4, 06 and 04 address lengths, 00 01 request.

  3. Offset 0x16: the sender

    02 00 00 aa bb 01 and c0 a8 01 0a: "I'm 192.168.1.10 at 02:00:00:aa:bb:01." (c0 = 192, a8 = 168, 0a = 10.)

  4. Offset 0x20: the target

    Six zero bytes for the MAC we don't know yet, then c0 a8 01 01: "looking for 192.168.1.1". RFC 826 doesn't care what goes in THA for a request; most stacks send zeros.

  5. Offset 0x2a: padding, then FCS

    18 zero bytes to reach the 60-byte minimum before the FCS. The CRC-32 over bytes 0–59 is 0xE1A512CC, sent least-significant byte first as cc 12 a5 e1, just like the FCS in the Layers article.

And the router's reply. Compare it with the request: the operation is now 2, the router's addresses moved into the sender slots, and the laptop's moved into the target slots. The frame is now unicast, addressed straight to the laptop:

ARP reply: 64 bytes

0000  02 00 00 aa bb 01 02 00 00 cc dd 02 08 06 00 01
0010  08 00 06 04 00 02 02 00 00 cc dd 02 c0 a8 01 01
0020  02 00 00 aa bb 01 c0 a8 01 0a 00 00 00 00 00 00
0030  00 00 00 00 00 00 00 00 00 00 00 00 28 b4 cd e8

Same layout. Operation 00 02 at offset 0x14. FCS = CRC-32 of bytes 0–59 = 0xE8CDB428, sent as 28 b4 cd e8.

Why your capture says 42 bytes

Capture ARP on the machine that sends it and Wireshark shows a 42-byte frame: the capture is taken before the network card adds padding and FCS. Capture the same request on the machine that receives it and you'll usually see 60 bytes, padding included, FCS stripped. That's also why tcpdump on the receiver may say "length 46": it's counting the padded payload.

Start from an example

ARP message

Operation

The frame on the wire


    

Decode a captured frame

The ARP Cache

Broadcasting before every single packet would be absurd, so every host remembers the answers. The ARP cache (Linux calls it the neighbour table) maps IP addresses on the local network to MAC addresses, along with a little state about how fresh each entry is.

Looking at your own

On Linux, ip neigh shows the table. On the laptop, a minute after printing something:

$ ip neigh show
192.168.1.1 dev eth0 lladdr 02:00:00:cc:dd:02 REACHABLE
192.168.1.20 dev eth0 lladdr 02:00:00:aa:bb:03 STALE
192.168.1.99 dev eth0 FAILED

The router is REACHABLE (recently confirmed), the printer is STALE (we have an answer, but it's getting old), and 192.168.1.99 is an address we tried and nobody answered, so it has no MAC at all.

The older arp -a command exists on Linux, macOS and Windows, with three slightly different looks:

# Linux (net-tools)
? (192.168.1.1) at 02:00:00:cc:dd:02 [ether] on eth0
? (192.168.1.20) at 02:00:00:aa:bb:03 [ether] on eth0
# macOS (drops leading zeros in each byte)
? (192.168.1.1) at 2:0:0:cc:dd:2 on en0 ifscope [ethernet]
# Windows
Interface: 192.168.1.10 --- 0xc
  Internet Address      Physical Address      Type
  192.168.1.1           02-00-00-cc-dd-02     dynamic
  192.168.1.20          02-00-00-aa-bb-03     dynamic
  192.168.1.255         ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static

The ? is where a hostname would go if a reverse DNS lookup found one. Windows also lists static entries for the broadcast address and multicast groups. Those aren't learned from anyone: they're computed, because broadcast and multicast MACs follow fixed rules (the 01:00:5e prefix for IPv4 multicast is the one we decoded in the Ethernet article). You can add static entries for unicast addresses too, with ip neigh add ... nud permanent on Linux or arp -s on most systems. Static entries never expire and are never overwritten by ARP traffic, which will matter when we get to spoofing.

How long does an entry last?

RFC 826 deliberately left aging to implementers ("outside the scope of this protocol"), and they all chose differently. There's a real trade-off: keep entries too long and a replaced device stays unreachable until the old entry expires; keep them too short and hosts broadcast constantly.

Linux, and Windows since Vista, use a small state machine borrowed from IPv6's Neighbor Discovery (RFC 4861). Here's how a Linux entry moves through it with default settings:

  1. INCOMPLETE: asked, no answer yet

    Up to 3 broadcasts, 1 s apart. A reply → REACHABLE; silence → FAILED.

  2. REACHABLE: recently confirmed

    Becomes STALE after the reachable time, randomized between 15 and 45 s (half to one-and-a-half times a 30 s base).

  3. STALE: have a MAC, unconfirmed lately

    Still used! The first packet sent to it moves it to DELAY.

  4. DELAY: waiting for proof of life

    If an upper layer confirms within 5 s (e.g. TCP sees ACKs coming back), back to REACHABLE with no ARP at all. Otherwise → PROBE.

  5. PROBE: actively checking

    Up to 3 unicast requests, 1 s apart, to the cached MAC. Reply → REACHABLE; silence → FAILED.

  6. FAILED: nobody answered

    Packets to it are dropped; the sender gets "host unreachable".

  7. PERMANENT: static entry

    Never changes.

Two details are worth noticing. First, a STALE entry is still used immediately; the host doesn't stop and ask. It sends the packet and then checks, so normal traffic never waits for ARP once an entry exists. Second, the check prefers evidence that's already there: if TCP is getting acknowledgments from that host, the MAC must be right, and no ARP is sent. Unused stale entries are eventually garbage-collected, but on a small home network (Linux keeps at least 128 entries before it bothers collecting) they can linger for a long time.

Other systems simply give each entry a fixed lifetime. Here's how the defaults compare:

System Default lifetime of a learned entry
Linux Reachable for 15–45 s, then STALE (re-verified on use)
Windows (Vista and later) Reachable for 15–45 s, then stale, similar to Linux
macOS (and other BSDs) 20 minutes (net.link.ether.inet.max_age = 1200 s)
Cisco IOS routers 4 hours (arp timeout 14400 s)

Treat these as typical defaults, not guarantees: they're all tunable, and they differ across versions. The Cisco number looks odd next to the others, but it's long on purpose: a router may have thousands of hosts behind an interface, and re-ARPing for all of them constantly would be a broadcast storm of its own. Its length is also why a Cisco router can keep sending to the old MAC for hours after you swap a device, unless the new device announces itself (more on that shortly).

Local or Remote?

So far the laptop has only ARPed for things on its own network. What happens when it wants to reach the web server at 203.0.113.80?

The answer is the single most important idea in this article: a host never ARPs for an address that isn't on its own network. ARP is a broadcast, and broadcasts don't cross routers. If the laptop shouted "who has 203.0.113.80?", nobody on the LAN would answer, and the server, thousands of kilometres away, would never hear it.

Instead, before ARP even starts, the host makes a routing decision. Its network settings include an address, a subnet mask, and a default gateway:

Address:          192.168.1.10
Subnet mask:      255.255.255.0      (also written /24)
Default gateway:  192.168.1.1

The mask says which part of an address identifies the network. A 255 byte means "this byte must match"; a 0 byte means "anything goes". To test whether a destination is local, the host keeps only the network part of both addresses (a bitwise AND with the mask) and compares:

To the printer: local

192.168.1.20 AND 255.255.255.0 = 192.168.1.0
192.168.1.10 AND 255.255.255.0 = 192.168.1.0
Same network. The next hop is the printer itself: ARP for 192.168.1.20, and send the frame to the printer's MAC.

To the web server: remote

203.0.113.80 AND 255.255.255.0 = 203.0.113.0
192.168.1.10 AND 255.255.255.0 = 192.168.1.0
Different network. The next hop is the default gateway: ARP for 192.168.1.1, and send the frame to the router's MAC.

Send an IP packet to D Is D on my subnet? (D AND mask) == (my IP AND mask) yes no Next hop = D itself e.g. printer 192.168.1.20 Next hop = default gateway 203.0.113.80 → use 192.168.1.1 Next hop's MAC in the ARP cache? yes no Send frame to that MAC IP destination is still D Queue packet, broadcast ARP request for the next hop

Look back at the 95-byte frame from the Layers article with this in mind. Its IP header says destination 203.0.113.80, but its Ethernet header says destination 02:00:00:cc:dd:02, the router's MAC. That's not a contradiction: the IP address is where the packet is ultimately going, and the MAC address is the next box that will carry it there. The router receives the frame, sees an IP destination that isn't its own, and forwards the packet out of its Internet-side interface, inside a brand-new Ethernet (or other) frame. If that next link is Ethernet too, the router does its own ARP there, for its own next hop. Every hop across the Internet repeats this: ARP resolves just one link at a time.

Two destinations, two scopes

The IP destination stays the same from end to end. The MAC destination is rewritten at every router and only ever names the next device on the current link. ARP's job is to fill in that second one, and only for addresses that are actually on the link.

In pseudocode, that decision sits right in front of the resolve function from earlier:

function send_ip(packet):
    if (packet.dst & my_mask) == (my_ip & my_mask):
        next_hop = packet.dst              # on my link: deliver directly
    else:
        next_hop = default_gateway         # elsewhere: hand it to the router
    mac = resolve(next_hop, packet)        # ARP, or a cache hit
    send_frame(dst = mac, src = my_mac, ethertype = 0x0800, payload = packet)

Real hosts consult a full routing table rather than a single "local or gateway" test, and masks aren't always whole bytes like 255.255.255.0. The next article, IPv4 Addressing, takes subnets and masks apart properly; and Routing Basics covers what the router does with the packet next. A classic misconfiguration falls straight out of this logic, though: give a host the wrong mask, and it will either ARP for remote addresses (and get no answer) or send local traffic to the router (which works, slowly, if the router is kind enough to forward it back).

Try It: ARP on a Small LAN

Here's our four-device network with the Internet beyond the router. Pick a sender and a destination IP and watch the request flood, the reply come back, and every cache update. Try a remote address and see who actually gets asked. The gratuitous-ARP button belongs to the next section, so come back to it.

Send a ping

ARP caches

A * marks an entry the host learned from someone else’s request. To keep things readable this simulator starts those as REACHABLE; Linux actually files them as STALE, since nothing has confirmed them yet. Timers run on the simulated clock below, which stops while a frame is on the wire.

Clock and aging

When ticked, an echo reply counts as proof of life for the neighbour it came through, the way TCP ACKs do on a real host. Real ping doesn’t confirm, so by default a STALE entry goes through DELAY and PROBE.

Gratuitous ARP

For the next section: a host broadcasts an ARP request for its own address. Only hosts that already have an entry for it update.

Event log

Gratuitous ARP

Remember the merge rule: when any ARP packet arrives, every host that already has the sender's IP in its cache updates the MAC. That opens up a neat trick. A host can broadcast an ARP packet about itself, without needing an answer, just to make everyone who knows it refresh their caches. This is a gratuitous ARP: an ARP request in which the sender and target IP are both the host's own address.

ARP, Request who-has 192.168.1.30 tell 192.168.1.30, length 28

That's the NAS "asking" for its own address. Nobody is supposed to answer. It's an announcement wearing a question's clothes. (Some systems send the same announcement as an unsolicited ARP reply instead; both forms are in use, and receivers generally handle both.)

It's used in three main situations:

  1. Announcing yourself on arrival

    When an interface comes up or gets a new address, the host broadcasts a gratuitous ARP. Any host with a stale entry for that IP updates it, and every switch on the way learns which port the host is on (the switch learns from the frame's source MAC, as in the Ethernet article). This is the announcement that fixes the "laptop moved to another port" problem almost instantly.

  2. Failover

    High-availability pairs (two firewalls, two database servers) often share a floating IP address. When the standby takes over, that IP suddenly lives at a different MAC address, so the standby immediately broadcasts a gratuitous ARP and every host's cache points at the new machine at once, instead of over the next several minutes or hours. Router redundancy protocols such as VRRP go a step further and move a virtual MAC along with the IP, so hosts' caches never change at all; the gratuitous ARP on takeover mainly re-teaches the switches which port that MAC now lives on.

  3. Hardware changes

    Swap a network card, or move a virtual machine to another host, and the IP address suddenly lives at a new MAC or behind a new switch port. A gratuitous ARP tells everyone right away.

Note what gratuitous ARP can't do: on hosts that follow the merge rule, it only updates entries that already exist. Hosts that have never talked to the NAS don't add it. Linux makes this a setting (arp_accept); by default it updates existing entries from gratuitous ARP but doesn't create new ones.

Look before you leap: address conflict detection

What if two devices are configured with the same IP? Before 2008, the usual check was the single gratuitous ARP at startup: if anyone answered it, there was a conflict. But announcing first and checking second means you've already poisoned your neighbours' caches with your MAC before discovering the address wasn't yours. RFC 5227 fixed this with a probe before you announce procedure called Address Conflict Detection (ACD):

  1. Probe

    After a random wait of up to 1 second, send three ARP probes, 1 to 2 seconds apart. A probe is an ARP request with the candidate address in TPA and the sender IP set to 0.0.0.0. The all-zero sender is the clever bit: it asks "is anyone using this?" without claiming the address, so nobody's cache gets updated by it.

  2. Listen

    If, during probing, any ARP packet arrives whose sender IP is the candidate address, someone already owns it: conflict. Same if another host's probe for the same address shows up (two machines picking the same address at the same moment). The host must pick a different address, or report an error.

  3. Announce

    Two seconds after the last probe, if there's been no conflict, the address is ours. Send two ARP announcements (gratuitous ARP: SPA = TPA = the new address), 2 seconds apart.

  4. Keep watching, and defend

    Even after the address is in use, a conflicting ARP from someone else can arrive. The host may defend its address once with a fresh announcement, but if a second conflict arrives within 10 seconds, it should give the address up rather than fight forever (routers and servers are allowed to defend indefinitely, rate-limited).

Here's a probe from the NAS checking 192.168.1.30 before using it:

ARP, Request who-has 192.168.1.30 tell 0.0.0.0, length 28

That "duplicate IP address" warning your operating system pops up is this mechanism, or a close cousin of it, catching a conflict. DHCP clients use the same idea: RFC 2131 recommends that a client ARP for an address it has just been offered before using it, and decline the address if anyone answers.

Proxy ARP

Sometimes a router answers ARP requests for addresses that aren't its own. This is proxy ARP (RFC 1027, 1987). Suppose a host is misconfigured and thinks a remote address is local, so it broadcasts "who has 203.0.113.80?" A router with proxy ARP enabled knows it can reach 203.0.113.80, so it replies with its own MAC: "203.0.113.80 is at 02:00:00:cc:dd:02." The host happily sends the packet to the router, which forwards it. The host never needed to know a router was involved.

That's both the appeal and the problem. Proxy ARP was invented in the 1980s to let hosts that didn't understand subnets keep working when networks were split up, and it still quietly papers over mistakes and supports some setups (certain VPN and mobile-IP arrangements, and some Wi-Fi access points answer ARP on behalf of sleeping phones so the phones don't have to wake up). But it also hides misconfigurations, makes many IPs share one MAC in everyone's caches, and enlarges the set of devices answering ARP. Many network operators turn it off unless they need it.

ARP Spoofing

ARP was designed in 1982 for a network of trusted machines, and it shows. Look at what we've established:

  • An ARP reply is not authenticated. Nothing proves that the sender of "192.168.1.1 is at …" is actually 192.168.1.1. ARP just believes SHA and SPA.
  • ARP is stateless. Many implementations will update an existing cache entry from any ARP packet that mentions the IP, whether or not they asked a question. That's the merge rule, and it's what gratuitous ARP depends on.
  • Everyone on the LAN can send ARP packets. No permission is needed.

Put those together and any device on the local network can claim any IP address. This is ARP spoofing, or ARP cache poisoning. Imagine a fifth device on our network, a compromised machine at 192.168.1.66 with MAC 02:00:00:ee:ee:66. It sends two unsolicited replies:

  • To the laptop: "192.168.1.1 is at 02:00:00:ee:ee:66."
  • To the router: "192.168.1.10 is at 02:00:00:ee:ee:66."

Both already have entries for each other, so both update. Now:

Laptop 192.168.1.10 Router 192.168.1.1 the path everyone thinks they're using cache: 192.168.1.1 → 02:00:00:ee:ee:66 cache: 192.168.1.10 → 02:00:00:ee:ee:66 Attacker .66 · 02:00:00:ee:ee:66 "192.168.1.1 is at ee:ee:66" "192.168.1.10 is at ee:ee:66" actual traffic: laptop → attacker → router IP addresses are untouched; only the MAC each side uses for the other has changed.

Every frame the laptop sends "to the router" now goes to the attacker's MAC, and the switch dutifully delivers it to the attacker's port. If the attacker forwards each packet on to the real router (and the router's replies back to the laptop), nothing visibly breaks. The laptop and router keep working and have no idea that every packet now passes through a third machine. This is a man-in-the-middle position, and from it an attacker can read unencrypted traffic, alter it, or simply drop it (a denial of service). The forged replies have to be repeated every few seconds, because real ARP traffic would otherwise correct the caches.

The attack only works from inside the broadcast domain: ARP never crosses a router. But "inside" includes every device on a coffee-shop Wi-Fi network, every compromised smart plug, and every visitor's laptop plugged into an office wall socket.

Defences

Since ARP itself can't be fixed without replacing it everywhere, defences come from around it:

  1. Dynamic ARP Inspection (on the switch)

    Managed switches can check every ARP packet arriving on an untrusted (user-facing) port against a table of which IP really belongs to which MAC on which port, and drop any that don't match. Where does that table come from? From DHCP snooping: the switch watches DHCP traffic and records each address the DHCP server hands out. The two features go together, and on an enterprise network they shut down ARP spoofing at the first switch. (The DHCP article covers the other half.)

  2. Static entries (for the few that matter)

    A static ARP entry is never overwritten by ARP traffic, so pinning the gateway's MAC on a critical server makes that server immune. It doesn't scale: every static entry is one more thing to update by hand when hardware changes.

  3. Isolation and access control

    Fewer devices in a broadcast domain means fewer potential attackers. Guest VLANs, Wi-Fi "client isolation" (which stops wireless clients from talking to each other directly), and port authentication with 802.1X all shrink the set of machines that could send a forged reply.

  4. Monitoring

    Tools that watch ARP traffic can alert when an IP's MAC suddenly changes, or when one MAC claims several IPs. They detect rather than prevent, and failovers trigger them too, but they make a quiet attack noisy.

The real answer: don't trust the network

Every defence above tries to keep the local network honest. The more robust approach is to assume it isn't. With TLS (HTTPS), SSH, or a VPN, an attacker in the middle sees only ciphertext, can't modify it without detection, and can't impersonate the server without its private key. ARP spoofing can still redirect or block traffic, but it can no longer read or alter it. This is a large part of why the web moved to HTTPS everywhere: the network between you and the server, starting with the first hop, isn't trustworthy.

IPv6: Neighbor Discovery

IPv6 doesn't use ARP. It solves the same problem with Neighbor Discovery (ND), and the shape will look familiar:

ARP (IPv4) Neighbor Discovery (IPv6)
Its own EtherType, 0806 Ordinary ICMPv6 messages inside IPv6 packets
Request: "who has…?" Neighbor Solicitation (ICMPv6 type 135)
Reply: "…is at" Neighbor Advertisement (ICMPv6 type 136)
Request sent to broadcast ff:ff:ff:ff:ff:ff Solicitation sent to a solicited-node multicast group
Gratuitous ARP / ACD probe Unsolicited advertisement / Duplicate Address Detection
Cache aging left to the implementer Neighbor Unreachability Detection built in: the REACHABLE, STALE, DELAY, PROBE states come from here

The biggest improvement is the fourth row: who receives the question. IPv6 has no broadcast at all. Instead, every IPv6 address automatically joins a multicast group named after its last 24 bits: ff02::1:ff followed by those 24 bits. Suppose the router's link-local IPv6 address is fe80::ff:fecc:dd02 (how that address is built from its MAC is a story for the IPv6 article). Its last 24 bits are cc:dd:02, so:

  1. Solicited-node group

    ff02::1:ffcc:dd02

  2. Mapped to an Ethernet multicast MAC

    IPv6 multicast maps to 33:33 followed by the last 32 bits of the group address: 33:33:ff:cc:dd:02. That's the 33:33:… family we decoded in the Ethernet article.

  3. Who wakes up?

    Only network cards subscribed to that multicast address pass the frame up. On our LAN, that's just the router. The laptop, printer and NAS have different last-24-bit groups, so their hardware filters the solicitation out without ever interrupting the operating system.

That's the same "shout, then reply" pattern as ARP, but the shout is aimed at a group of, almost always, exactly one. On a network with thousands of hosts, that's a real saving.

Neighbor Discovery isn't automatically safer, though. Neighbor Advertisements are just as unauthenticated as ARP replies, so the same spoofing works, and the defences mirror ARP's: switch-level ND inspection (and RA Guard against rogue routers) and, above all, encryption. A cryptographic fix, SEND (RFC 3971), exists but has seen very little deployment.

Where to Go Next

  • IPv4 Addressing: masks, prefixes and subnets properly, including how the "is it local?" test works with masks that aren't whole bytes.
  • IPv6: 128-bit addresses, how a host builds its own address from its MAC, and the rest of Neighbor Discovery.
  • DHCP: where the laptop's IP, mask and default gateway came from in the first place, and the snooping that makes Dynamic ARP Inspection possible.
  • VLANs: splitting one switch into separate broadcast domains, so ARP broadcasts (and ARP attackers) stay contained.
  • TLS (Encryption): why a man in the middle can't read your HTTPS traffic even after poisoning your cache.

Key Takeaways

  • IP addresses say where a packet is going; Ethernet needs the MAC of the next device on the wire. ARP discovers that mapping at run time.
  • A request is broadcast ("who has 192.168.1.1? tell 192.168.1.10"); the reply is unicast ("192.168.1.1 is at 02:00:00:cc:dd:02"). The target learns the asker from the request for free.
  • The ARP message is 28 bytes (EtherType 0806; HTYPE 1, PTYPE 0800, HLEN 6, PLEN 4, OPER 1 or 2, then SHA, SPA, THA, TPA). With the 14-byte header it's 42 bytes, so it gets 18 bytes of padding and a 4-byte FCS: a 64-byte minimum frame.
  • Hosts cache answers. Lifetimes vary a lot by OS, from tens of seconds (Linux, Windows, with re-verification) to 20 minutes (macOS) to 4 hours (Cisco routers).
  • A host ARPs only for addresses on its own subnet. For anything remote it ARPs for the default gateway, and the frame carries the router's MAC while the IP header keeps the real destination.
  • Gratuitous ARP announces an address (on startup, failover, hardware change); RFC 5227 probes with sender IP 0.0.0.0 before announcing, to detect conflicts.
  • ARP has no authentication, so any device on the LAN can poison caches and sit in the middle. Switch features (Dynamic ARP Inspection with DHCP snooping) help; encryption like TLS is the real defence.
  • IPv6 replaces ARP with Neighbor Discovery: ICMPv6 solicitations sent to a solicited-node multicast group instead of a broadcast.

Our laptop has been relying on one quiet assumption throughout: that 255.255.255.0 tells it which addresses are "local". Next up: IPv4 Addressing, where we take that mask apart bit by bit.