ARP: from IP to MAC
ARP (Address Resolution Protocol) finds the MAC address of a device on the same LAN from its IPv4 address. A switch forwards frames by MAC, not IP, so every packet on a LAN needs ARP first.
48.1 Why is it used?
- The PC 192.168.68.10 knows the server's IP (192.168.68.20) but the Ethernet frame needs a destination MAC.
- The switch only looks at MAC addresses to forward a frame.
- ARP answers 'who has this IP?' and works between Layer 2 and Layer 3.
- IPv6 does not use ARP; it uses NDP (Neighbor Discovery).
48.2 How it works
- Step 1
1.PC wants to ping 192.168.68.20: dst IP known, dst MAC unknown
- Step 2
2.PC broadcasts ARP request to ff:ff:ff:ff:ff:ff: 'Who has 192.168.68.20? Tell 192.168.68.10'
- Step 3
3.Switch floods it to every port; laptop and printer see 'not me' and drop it
- Step 4
4.Server replies unicast: '192.168.68.20 is-at 62:dd:87:d2:34:09'
- Step 5
5.PC stores it in its ARP cache; the ping frame now goes to the right MAC
- Step 6
6.Bonus: the server also learnt the PC's MAC from the request
| Message | Destination MAC | Sent by |
|---|---|---|
| ARP request | Broadcast ff:ff:ff:ff:ff:ff | Device that needs the MAC |
| ARP reply | Unicast to the requester | Owner of the IP |
| Gratuitous ARP | Broadcast (sender IP = target IP) | Device announcing itself |
| Proxy ARP reply | Unicast, with the router's MAC | Router on behalf of another network |
48.3 Practical: ARP on the first ping
ip neigh showtimeout 8 tcpdump -l -n -e -i eth0 arp > /tmp/arp1.txt &ping -c 2 192.168.68.20cat /tmp/arp1.txtip neigh show$ ip neigh show$ ping -c 2 192.168.68.2064 bytes from 192.168.68.20: icmp_seq=1 ttl=64 time=4.07 ms64 bytes from 192.168.68.20: icmp_seq=2 ttl=64 time=12.9 ms2 packets transmitted, 2 received, 0% packet loss$ cat /tmp/arp1.txt0e:ee:fb:15:e4:4c > ff:ff:ff:ff:ff:ff Request who-has 192.168.68.20 tell 192.168.68.1062:dd:87:d2:34:09 > 0e:ee:fb:15:e4:4c Reply 192.168.68.20 is-at 62:dd:87:d2:34:09$ ip neigh show192.168.68.20 dev eth0 lladdr 62:dd:87:d2:34:09 REACHABLEThe cache was empty before the ping; the first line of the capture is the broadcast request, the second the unicast reply.
48.4 ARP cache and its states
| State (Linux) | Meaning |
|---|---|
| REACHABLE | Just confirmed (base reachable time about 30 s) |
| STALE | Old but still used |
| DELAY / PROBE | Re-checked on the next packet |
| FAILED | No reply, entry removed |
| PERMANENT | Static entry, never changed by ARP replies |
$ sleep 45; ip neigh show192.168.68.20 dev eth0 lladdr 62:dd:87:d2:34:09 STALE$ ping -c 1 192.168.68.20 > /dev/null$ ip neigh show192.168.68.20 dev eth0 lladdr 62:dd:87:d2:34:09 DELAY- Caching avoids a broadcast before every packet.
- Linux: ip neigh show; Windows: arp -a.
48.5 Gratuitous ARP
- An ARP for your own IP that nobody asked for: sent at boot or when the NIC changes.
- Neighbours update their caches; it also detects duplicate IPs.
- Used in failover: a backup server takes over the IP and tells everyone at once.
- Recognise it: sender IP = target IP.
srv$ arping -U -c 1 -I eth0 192.168.68.20ARPING 192.168.68.20 from 192.168.68.20 eth0Sent 1 probes (1 broadcast(s))Received 0 response(s)pc$ cat /tmp/arp2.txt62:dd:87:d2:34:09 > ff:ff:ff:ff:ff:ff Request who-has 192.168.68.20 tell 192.168.68.2048.6 Proxy ARP
- A router answers ARP on behalf of a host on another network, with its own MAC.
- Lab: the PC's mask was wrongly /24 instead of /25, so it ARPed directly for 192.168.68.140.
- The router (proxy_arp = 1, MAC 66:e2:cc:cc:97:e2) replied, and forwarded the PC's packets.
- First reply took about 776 ms because Linux deliberately delays proxy replies.
# rtrsysctl net.ipv4.conf.eth0.proxy_arpip -br link show eth0# pc: mask set to /24 by mistakeip addr del 192.168.68.10/25 dev eth0ip addr add 192.168.68.10/24 dev eth0ping -c 2 192.168.68.140ip neigh show 192.168.68.140$ sysctl net.ipv4.conf.eth0.proxy_arpnet.ipv4.conf.eth0.proxy_arp = 1$ ip -br link show eth0eth0@if759 UP 66:e2:cc:cc:97:e2$ ping -c 2 192.168.68.14064 bytes from 192.168.68.140: icmp_seq=1 ttl=63 time=776 ms64 bytes from 192.168.68.140: icmp_seq=2 ttl=63 time=0.183 ms$ ip neigh show 192.168.68.140192.168.68.140 dev eth0 lladdr 66:e2:cc:cc:97:e2 REACHABLE48.7 ARP spoofing (defensive view)
- Step 1
1.PC cache: 192.168.68.20 -> 62:dd:87:d2:34:09 (real server)
- Step 2
2.Attacker 192.168.68.66 broadcasts a fake gratuitous ARP for 192.168.68.20
- Step 3
3.ARP has no authentication: the PC accepts it
- Step 4
4.PC cache now: 192.168.68.20 -> 62:a0:cc:d9:d6:25 (attacker)
- Step 5
5.PC's packets go to the attacker: man in the middle
# evil (192.168.68.66): fake claimip addr add 192.168.68.20/32 dev eth0arping -U -c 2 -I eth0 -s 192.168.68.20 192.168.68.20# pcip neigh show 192.168.68.20# pc: static entry (defense)ip neigh replace 192.168.68.20 lladdr 62:dd:87:d2:34:09 dev eth0 nud permanent$ ip neigh show 192.168.68.20192.168.68.20 dev eth0 lladdr 62:a0:cc:d9:d6:25 STALE# after the static entry, the same fake arping again:$ ip neigh show 192.168.68.20192.168.68.20 dev eth0 lladdr 62:dd:87:d2:34:09 PERMANENT48.8 Defending against spoofing
- Dynamic ARP Inspection (DAI) on managed switches: every ARP reply is checked against the DHCP snooping table.
- Static ARP entries for the gateway and critical servers (fine for a few devices; DAI scales better).
- arpwatch-style tools alert when a MAC changes.
- Encryption (HTTPS, SSH, VPN) keeps data safe even if a MITM happens.
48.9 Common mistakes
- Thinking ARP can find the MAC of an internet server: ARP broadcasts never cross a router.
- For 8.8.8.8 the PC ARPs for the gateway; dst MAC = router, dst IP stays 8.8.8.8.
- Every router hop builds a new Ethernet header (and does its own ARP).
- A wrong subnet mask can hide behind proxy ARP and look like it works.
48.10 Interview tips
- ARP resolves IPv4 to MAC, between L2 and L3.
- Request is broadcast, reply is unicast; result cached with a timeout (REACHABLE, STALE...).
- No authentication, so spoofing is possible: defend with DAI, static entries, encryption.
- IPv6 uses NDP instead of ARP.