ARP & neighbour discovery
Explain how IP addresses are resolved to MAC addresses and inspect the ARP cache.
By Invicly Tech, , in Computer Networking. About 10 minutes to read.
In short
ARP finds the MAC address that belongs to an IPv4 address on the local network. A host broadcasts who-has for the IP and the owner replies directly with its MAC, which the asker caches. To reach a remote network a host ARPs for its default gateway, not for the final destination.
Explained simply
To send data on a local network, a computer needs two addresses for the receiver: its IP address (which it usually already knows) and its MAC address (which the network card actually uses). ARP, the Address Resolution Protocol, finds the MAC address for a given IPv4 address.
It works like shouting a question in a room. Your computer broadcasts: who has 10.0.0.1? Every device on the LAN hears it, but only the one with that IP answers, directly to you: 10.0.0.1 is at aa:bb:cc:dd:ee:01. Your computer saves the answer in its ARP cache so it does not have to ask again for a while.
ARP only works inside your own network. If you want to reach a server on the internet, your computer does not ARP for that server. It knows the server is on another network, so it ARPs for its default gateway (the router) and sends everything to the router's MAC.
IPv6 does not use ARP. It uses Neighbour Discovery, which does the same job with ICMPv6 messages sent to special multicast addresses instead of broadcasts, so fewer devices are disturbed.
Press Play on a diagram to walk through it one step at a time.
- Host 10.0.0.5 to Switch: Broadcast: who has 10.0.0.1? tell 10.0.0.51Broadcast: who has 10.0.0.1? tell 10.0.0.5
- Switch to Router 10.0.0.1: Flooded to all ports2Flooded to all ports
- Router 10.0.0.1 to Switch: Unicast reply: 10.0.0.1 is at aa:bb:cc:dd:ee:013Unicast reply: 10.0.0.1 is at aa:bb:cc:dd:ee:01
- Switch to Host 10.0.0.5: Forwarded; host caches the mapping4Forwarded; host caches the mapping
- 1Packet to send
Destination IP, e.g. 142.250.74.46
- 2Same subnet?
Compare with own IP and mask
- 3Yes: ARP target
Resolve the destination itself
- 4No: ARP gateway
Resolve the default gateway's IP
- 5Build frame
Dst MAC = result, dst IP unchanged
In depth
Inside an ARP packet
ARP for IPv4 over Ethernet is a 28-byte message carried directly in an Ethernet frame with EtherType 0x0806, not inside IP. It contains: hardware type 1 (Ethernet), protocol type 0x0800 (IPv4), hardware length 6, protocol length 4, an opcode (1 for request, 2 for reply), then sender MAC, sender IP, target MAC and target IP.
In a request, the target MAC is all zeros, because that is what the sender wants to learn, and the frame goes to ff:ff:ff:ff:ff:ff. The reply swaps the roles and is unicast back to the asker. A useful detail: any host that receives a request for its own IP also caches the sender's mapping straight away, because it will almost certainly need to reply to it soon.
- EtherType 0x0806, 28-byte payload
- Opcode 1 = request, 2 = reply
- Request: target MAC 00:00:00:00:00:00, sent to broadcast
- Reply: unicast to the requester
Linux neighbour states and timers
Linux shows ARP entries with ip neigh, and each has a state. INCOMPLETE means a request was sent and no reply has arrived. REACHABLE means the mapping was confirmed recently, by a reply or by TCP traffic making progress. After the reachable time (base_reachable_time is 30 seconds, randomised between 15 and 45) it becomes STALE: still usable, but unverified. When a STALE entry is used, it moves to DELAY, then PROBE, where the kernel sends unicast ARP requests to check. If nobody answers, the entry becomes FAILED.
Other systems are more relaxed: Windows keeps entries for a short random time, while Cisco routers keep ARP entries for 4 hours by default. Static entries show as PERMANENT and never expire.
- 1INCOMPLETE
Request sent, waiting for a reply
- 2REACHABLE
Confirmed in the last 15 to 45 s
- 3STALE
Usable but unverified
- 4DELAY then PROBE
Used again, so check with unicast ARP
- 5REACHABLE or FAILED
Reply confirms it, silence fails it
- Back to step 1
Gratuitous ARP, probes and failover
A gratuitous ARP is one nobody asked for: the sender IP and target IP are both the host's own address. It has two uses. First, it announces a new or moved mapping. When a VRRP or keepalived pair fails over, the new active node sends gratuitous ARPs so every host and switch immediately updates its cache and MAC table to the new owner of the virtual IP. Without it, traffic would keep going to the dead node until the old entries expired.
Second, detecting conflicts. Before using an address, a host can send an ARP probe (RFC 5227) with sender IP 0.0.0.0, asking who has this address. Any reply means a duplicate. On Linux, arping -D runs this check, and arping -U sends an unsolicited announcement.
- arping -D -I eth0 10.0.0.50: is this address in use?
- arping -U -I eth0 10.0.0.50: announce my mapping
- keepalived sends gratuitous ARPs after failover
IPv6 Neighbour Discovery
IPv6 replaces ARP with Neighbour Discovery (RFC 4861), carried in ICMPv6. To resolve an address, a host sends a Neighbour Solicitation (type 135) to the target's solicited-node multicast address: ff02::1:ff followed by the last 24 bits of the target address. Only hosts whose addresses end in those bits listen, so almost nobody else is disturbed. The owner answers with a Neighbour Advertisement (type 136).
ND also does jobs ARP never did. Routers send Router Advertisements (type 134) with prefixes and the default gateway, and hosts can ask for one with a Router Solicitation (type 133). Duplicate Address Detection checks every new address before use. Redirect (type 137) tells a host about a better first hop. This is why blocking all ICMPv6 breaks IPv6 completely.
- Host 2001:db8::10 to Switch: NS to ff02::1:ff00:25 (MAC 33:33:ff:00:00:25)1NS to ff02::1:ff00:25 (MAC 33:33:ff:00:00:25)
- Switch to Server 2001:db8::25: Delivered to listeners of that group2Delivered to listeners of that group
- Server 2001:db8::25 to Switch: NA: 2001:db8::25 is at its MAC3NA: 2001:db8::25 is at its MAC
- Switch to Host 2001:db8::10: Unicast reply; host caches it4Unicast reply; host caches it
Learn it in 4 short steps
About 30m each. Track them with a timer in your plan.
- 1Trace an ARP request and reply~30m
- 2Inspect the ARP cache~30m
- 3Explain gratuitous ARP~30m
- 4Compare ARP with IPv6 neighbour discovery~30m
Key points
- Requests are broadcast; replies are unicast.
- Entries stay in the ARP cache for minutes and are refreshed.
- Gratuitous ARP announces your own IP, used after failover.
- IPv6 replaces ARP with Neighbour Discovery using ICMPv6 multicast.
Key terms
Tap a card to flip it. 0/4 known
Examples
ip neigh show # ARP / neighbour cache
sudo ip neigh flush dev eth0 # clear it
sudo tcpdump -i eth0 -nn arp # watch requests and replies
ping -c 1 10.0.0.1Watching ARP happen from an empty cache
Step 1: flush the neighbour cache so you start clean. Step 2: start tcpdump filtering only ARP. Step 3: ping the gateway once. You see one broadcast request (Request who-has 10.0.0.1 tell 10.0.0.5) and one reply (Reply 10.0.0.1 is-at aa:bb:cc:dd:ee:01). Step 4: ip neigh now shows the gateway as REACHABLE. Step 5: wait a minute and check again; it has turned STALE but stays in the cache and is reused without a new broadcast.
sudo ip neigh flush dev eth0
sudo tcpdump -i eth0 -nn -e arp &
ping -c 1 10.0.0.1
ip neigh show dev eth0
sleep 60; ip neigh show dev eth0 # REACHABLE -> STALE
sudo kill %1Finding a duplicate IP address
A printer goes on and off the network randomly. Suspect: another device took its IP. Step 1: run arping against the printer's IP; replies from two different MAC addresses prove a conflict. Step 2: look up both OUIs to identify the vendors. Step 3: find the rogue device on the switch with show mac address-table address for the unknown MAC, which gives the port. Step 4: fix it by giving the printer a DHCP reservation outside any static range.
sudo arping -I eth0 -c 4 10.0.0.40
# Unicast reply from 10.0.0.40 [00:1B:A9:11:22:33]
# Unicast reply from 10.0.0.40 [B8:27:EB:44:55:66] <- second owner
sudo arping -D -I eth0 -c 2 10.0.0.40; echo "exit=$?" # 1 = duplicate foundQuick reference
- ARP: EtherType 0x0806, request broadcast, reply unicast
- ip neigh show lists the cache; Windows uses arp -a; Cisco uses show ip arp
- States: INCOMPLETE, REACHABLE, STALE, DELAY, PROBE, FAILED, PERMANENT
- Off-subnet destinations: ARP for the default gateway, never the remote host
- arping -D checks for duplicates; arping -U announces your mapping
- IPv6 ND: RS 133, RA 134, NS 135, NA 136, Redirect 137 (ICMPv6 types)
- Solicited-node multicast: ff02::1:ff + last 24 bits of the address
Common mistakes
- Expecting to see the remote server's MAC; you only ever see the gateway's.
- Ignoring ARP spoofing on untrusted LANs.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
List your neighbour cache, find your gateway's entry and note its MAC address and state.
- Exercise 2medium
Add a permanent ARP entry for 10.0.0.50 with MAC 02:00:00:00:00:50, confirm it, and remove it again.
- Exercise 3hard
Work out the solicited-node multicast address and its multicast MAC for 2001:db8:a::12:3456, and write a tcpdump filter that shows only Neighbour Solicitations.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What is ARP spoofing?
- An attacker sends fake ARP replies claiming to be the gateway, so victims send their traffic through the attacker. Switches with DHCP snooping and Dynamic ARP Inspection drop such fake replies.
- How do I clear the ARP cache?
- On Linux run sudo ip neigh flush all. On Windows run arp -d * from an administrator prompt. On Cisco use clear arp-cache.
- What is proxy ARP?
- A router answering ARP requests on behalf of hosts on another network, so a host with a wrong mask can still reach them. It hides configuration mistakes and is usually disabled on modern networks.
- Does ARP work across a router?
- No. ARP broadcasts stay inside one broadcast domain. Each router hop does its own ARP on its next link.