Sub topic 10
Finding the next MAC address with ARP
This chapter assumes you know what an IPv4 address is, how the Ethernet frame is laid out, and that a host decides whether a destination is on its own subnet or needs a router. You should also be comfortable running commands in a terminal.
The problem ARP solves
An IP packet carries a destination IP address. An Ethernet frame needs a destination MAC address. The sender knows the IP address, but the network card cannot put an IP address in the frame header. It needs the MAC address of the device that should receive the frame on the local link.
The Address Resolution Protocol (ARP) maps an IPv4 address to a MAC address on the same link. IPv6 does the same job with Neighbor Discovery, which this chapter does not cover.
Whose MAC address do you need?
The sender asks ARP about the next hop, not always the final destination.
- If the destination IP is in the sender's own subnet, the next hop is the destination host.
- If it is in another subnet, the next hop is the default gateway (a router), so the sender resolves the router's MAC address.
The IP header still holds the final destination. Only the Ethernet header points at the next hop.
How a lookup works
ARP uses two messages. The request is broadcast to every device on the link. The reply is unicast back to the asker.
The steps are:
- Host A checks its ARP cache for the next hop's IP address. If an entry exists, it uses it and stops.
- If not, A broadcasts an ARP request. The Ethernet destination is
ff:ff:ff:ff:ff:ff, and the ARP body asks "who has this IP address?" - Every device on the link receives the request. Only the device that owns that IP address answers.
- The owner sends an ARP reply directly to A's MAC address, giving its own MAC address.
- A stores the pair in its ARP cache and sends the original frame.
ARP is carried directly in an Ethernet frame (EtherType 0x0806). It has no IP header, so ARP does not cross a router. It works only within one broadcast domain.
The ARP cache
Hosts keep a table of recent mappings so they do not broadcast for every packet. Entries expire after a short time, often seconds to minutes depending on the operating system, and are refreshed while in use.
View the table on Linux:
ip neighbour showEach line shows an IP address, the interface, the MAC address, and a state such as REACHABLE (recently confirmed), STALE (old, needs rechecking before trust), or FAILED (no reply).
To watch ARP happen, run a capture in one terminal and ping a local address in another:
sudo tcpdump -i eth0 -e -nn arpReplace eth0 with your interface name. If the target is already cached, you may see nothing, so clear the entry first with sudo ip neighbour flush all.
Common errors
- Incomplete or FAILED entries. The target did not answer. It may be off, on a different VLAN, or blocking ARP. Check cabling, VLAN membership, and the IP address you typed.
- Wrong subnet mask. The host believes a local address is remote (or the reverse), so it ARPs for the wrong device or sends traffic to the gateway needlessly.
- Duplicate IP addresses. Two devices answer for one IP address. The cache flips between MAC addresses and connections drop at random.
- ARP spoofing. ARP has no authentication. A malicious device can send replies claiming another device's IP address and capture its traffic. Switch features such as dynamic ARP inspection defend against this.
Exercise
Host A (192.168.1.10/24) sends a packet to 8.8.8.8. Which IP address does A look up with ARP, and which IP address appears in the destination field of the IP header?
Show answer
A looks up the MAC address of its default gateway, for example 192.168.1.1, because 8.8.8.8 is outside its subnet. The IP header's destination stays 8.8.8.8. The Ethernet destination is the gateway's MAC address.