SkillPilotAI

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

ARP request and reply on the LAN
  1. 1.PC wants to ping 192.168.68.20: dst IP known, dst MAC unknown

  2. 2.PC broadcasts ARP request to ff:ff:ff:ff:ff:ff: 'Who has 192.168.68.20? Tell 192.168.68.10'

  3. 3.Switch floods it to every port; laptop and printer see 'not me' and drop it

  4. 4.Server replies unicast: '192.168.68.20 is-at 62:dd:87:d2:34:09'

  5. 5.PC stores it in its ARP cache; the ping frame now goes to the right MAC

  6. 6.Bonus: the server also learnt the PC's MAC from the request

MessageDestination MACSent by
ARP requestBroadcast ff:ff:ff:ff:ff:ffDevice that needs the MAC
ARP replyUnicast to the requesterOwner of the IP
Gratuitous ARPBroadcast (sender IP = target IP)Device announcing itself
Proxy ARP replyUnicast, with the router's MACRouter on behalf of another network

48.3 Practical: ARP on the first ping

Terminal
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
Output
$ 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 REACHABLE

The 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
REACHABLEJust confirmed (base reachable time about 30 s)
STALEOld but still used
DELAY / PROBERe-checked on the next packet
FAILEDNo reply, entry removed
PERMANENTStatic entry, never changed by ARP replies
Output
$ 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.
Output
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.20

48.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.
Terminal
# 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
Output
$ 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 REACHABLE

48.7 ARP spoofing (defensive view)

ARP cache poisoning (own isolated lab only)
  1. 1.PC cache: 192.168.68.20 -> 62:dd:87:d2:34:09 (real server)

  2. 2.Attacker 192.168.68.66 broadcasts a fake gratuitous ARP for 192.168.68.20

  3. 3.ARP has no authentication: the PC accepts it

  4. 4.PC cache now: 192.168.68.20 -> 62:a0:cc:d9:d6:25 (attacker)

  5. 5.PC's packets go to the attacker: man in the middle

Terminal
# 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
Output
$ 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 PERMANENT

48.8 Defending against spoofing

  1. Dynamic ARP Inspection (DAI) on managed switches: every ARP reply is checked against the DHCP snooping table.
  2. Static ARP entries for the gateway and critical servers (fine for a few devices; DAI scales better).
  3. arpwatch-style tools alert when a MAC changes.
  4. 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.