LAN NetworksDiagnostics

ARP: How a PC Finds Another Device's MAC Address

Layer 2 and layer 3, broadcast request and unicast reply, the ARP cache and its expiry, the gateway's MAC, arp -a and ip neigh, gratuitous ARP, spoofing and Dynamic ARP Inspection, common mistakes.

  • Category: LAN Networks · Diagnostics
  • Published:
  • Editorial team: Alba Technology Academy
  • Reading time: about 11 minutes

A PC with the address 192.168.1.10 needs to send a packet to the router at 192.168.1.1. It knows the IP address, because DHCP handed it out, and yet that is not enough: the network card transmits Ethernet frames, and a frame is delivered to a MAC address. Who provides that address? That is the job of ARP, a small, quiet protocol at work in every IPv4 network. Let us look at how the broadcast request works, why the reply comes back as unicast, what the ARP cache contains and what happens when that cache is wrong: after a router is replaced, with a duplicate address or during an attack.

Two addresses for two layers

Every device on a local network has two addresses, used at different layers.

  • The IP address (layer 3, network) identifies the device logically and is the one applications use: 192.168.1.20, 203.0.113.10. It says who a packet is for, even on the other side of the world.
  • The MAC address (layer 2, data link) is the 48-bit address of the network card, for example 00:00:5e:00:53:0b. It says which interface on the local network should receive the frame. This is the address the switch works with, choosing the outgoing port from its MAC address table.

The IP packet travels inside an Ethernet frame. Before transmitting, the PC must fill in the frame header, and the destination MAC address field cannot be left empty. A translation from IP address to MAC address is therefore needed: it is provided by ARP, defined in 1982 by RFC 826.

The IP packet inside the Ethernet frame An Ethernet frame contains the destination MAC address, still unknown, the source MAC address 00:00:5e:00:53:0a, the type 0x0800 and the IP packet from 192.168.1.10 to 192.168.1.20, followed by the FCS check. MAC addresses belong to layer 2, IP addresses to layer 3. ARP finds the missing MAC. The PC knows the destination IP, but not the MAC Destination MAC ? ? ? Source MAC 00:00:5e:00:53:0a Type 0x0800 IP packet 192.168.1.10 → 192.168.1.20 FCS Layer 2 · Ethernet header Layer 3 · IP ARP answers the question: which MAC has the IP address 192.168.1.20?
Figure 1 — Simplified frame layout. Without the destination MAC address the frame cannot be sent.

The ARP message

ARP does not use IP: its messages travel directly inside Ethernet frames, with the type 0x0806 instead of IPv4's 0x0800. This is why an ARP message never crosses a router and always stays within the local network, that is, within the broadcast domain. For Ethernet and IPv4 the message is 28 bytes long and contains these fields:

FieldValue for Ethernet and IPv4Meaning
Hardware type1Ethernet
Protocol type0x0800IPv4
Address lengths6 and 4 bytes48-bit MAC, 32-bit IPv4
Operation code1 = request, 2 = replyMessage type
Sender MAC and IP00:00:5e:00:53:0a, 192.168.1.10Who is asking, or who is answering
Target MAC and IP00:00:00:00:00:00 (unknown), 192.168.1.20The address being looked up

Request in broadcast, reply in unicast

Take a small 192.168.1.0/24 network: PC A (192.168.1.10), PC B (192.168.1.20), PC C (192.168.1.30) and the firewall acting as gateway (192.168.1.1), all connected to the same switch. A needs to send data to B and does not yet have its MAC address.

  1. Request. A transmits a frame with the destination ff:ff:ff:ff:ff:ff, the broadcast address. The message essentially says: “Who has 192.168.1.20? Tell 192.168.1.10, 00:00:5e:00:53:0a.”
  2. Distribution. The switch forwards the broadcast to every port in the same VLAN except the one it came in on. Every device receives it and examines it.
  3. Selection. C and the firewall see that the target address is not theirs and do not reply. B recognises its own address and, while it is at it, records A's IP-to-MAC mapping in its own cache, which it will need to reply.
  4. Reply. B sends an ARP reply as unicast, straight to A's MAC: “192.168.1.20 is at 00:00:5e:00:53:0b.”
  5. Storage. A saves the IP–MAC pair in its ARP cache and finally sends the data frame, also as unicast. The switch, which has meanwhile learnt where A and B are, delivers it only on B's port.

The broadcast is the price of not knowing the destination: it is cheap, because the message is tiny, but every device on the network has to read it. In very large, flat networks broadcast traffic grows with the number of devices, which is one of the reasons to split them into VLANs.

ARP request in broadcast and reply in unicast On the left, PC A sends the ARP request to ff:ff:ff:ff:ff:ff: the switch forwards it to B, C and the gateway; only B replies, C and the gateway ignore it. On the right, B sends the reply as unicast to A's MAC, and A stores it in its ARP cache. 1 · Request in broadcast 2 · Reply in unicast SwitchSwitch PC A PC B PC C GW PC A PC B PC C GW repliesstores ignoresignoresnot receivednot received dst ff:ff:ff:ff:ff:ff“Who has 192.168.1.20?” dst 00:00:5e:00:53:0a“.20 is at 00:00:5e:00:53:0b”
Figure 2 — Simplified diagram. The request reaches every device on the local network, the reply only the one that asked.

The ARP cache and its expiry

Repeating the request for every packet would be wasteful. Every system therefore keeps the replies in an ARP cache (Linux calls it the neighbour table), a table that maps the IP addresses of the local network to their MACs. There are two kinds of entry:

  • dynamic entries, learnt from the replies and requests received; they stay valid for a limited time;
  • static entries, added by hand by the administrator or by the system (for example the broadcast address); they do not expire.

Expiry keeps track of changes: a replaced device, a new network card, an address given to different hardware. The lifetime is not set by RFC 826 and depends on the system and its version, so the following values are indicative:

  • Windows and Linux treat an entry as “reachable” for a few tens of seconds, starting from a base value of 30 seconds with some randomisation; after that they check it again the next time it is used, and delete it if the device no longer answers;
  • many routers and firewalls keep entries for several minutes, and some enterprise-class equipment for hours.

An expired entry is not a problem: the system simply asks again and the network barely notices. The real problem is the opposite: an entry that is still valid but wrong, as we will see in the common mistakes.

Off the subnet: the gateway's MAC

ARP only works within the local network. So what happens when A has to reach an Internet server, for example 203.0.113.10? First of all, A compares the destination with its own network using the subnet mask, as explained in the article on IP addresses and subnet masks.

  • If the destination is on the same network (192.168.1.20), A uses ARP to look up the MAC of the destination itself.
  • If the destination is off the subnet (203.0.113.10), A does not look for the MAC of the server, which could be anywhere: it looks up the MAC of the default gateway, 192.168.1.1.

The frame leaving A is therefore addressed to the firewall's MAC, while inside the IP packet the destination is still 203.0.113.10. The firewall receives the frame, reads the IP address, decides where to route it and builds a new frame for the next hop. At every hop between networks the MAC addresses change, while the IP addresses stay the same, apart from the address translation performed by NAT.

Same network or off the subnet PC A, 192.168.1.10/24, checks whether the destination is in the 192.168.1.0/24 network. If it is, it uses ARP to ask for the MAC of the destination 192.168.1.20 and sends the frame with destination MAC 00:00:5e:00:53:0b. If not, it asks for the MAC of the gateway 192.168.1.1 and sends the frame with destination MAC 00:00:5e:00:53:01 and destination IP 203.0.113.10. PC A · 192.168.1.10/24 has a packet to send Is the destination in 192.168.1.0/24? Yes · same network (192.168.1.20) ARP for the destination itself MAC dst 00:00:5e:00:53:0b IP dst 192.168.1.20 No · off the subnet (203.0.113.10) ARP for the gateway 192.168.1.1 MAC dst 00:00:5e:00:53:01 IP dst 203.0.113.10
Figure 3 — The destination MAC belongs to the next device on the path, the destination IP to the final one.

Viewing and clearing the cache

On Windows, macOS and Linux the arp -a command shows the cache. An indicative example on Windows, after the exchanges described above (the headings depend on the system language):

C:\> arp -a

Interface: 192.168.1.10 --- 0xb
  Internet Address      Physical Address      Type
  192.168.1.1           00-00-5e-00-53-01     dynamic
  192.168.1.20          00-00-5e-00-53-0b     dynamic
  192.168.1.255         ff-ff-ff-ff-ff-ff     static

On Linux the modern tool is ip neigh, which also shows the state of each entry:

$ ip neigh
192.168.1.1 dev eth0 lladdr 00:00:5e:00:53:01 REACHABLE
192.168.1.20 dev eth0 lladdr 00:00:5e:00:53:0b STALE
192.168.1.30 dev eth0  FAILED

REACHABLE means a recently confirmed entry, STALE an entry that can still be used but will be checked again on next use, FAILED a request that went unanswered. To clear the cache, use arp -d * or netsh interface ip delete arpcache on Windows (as administrator) and sudo ip neigh flush dev eth0 on Linux. Firewalls show their table too: on OPNsense it is among the interface diagnostics tools (menus may vary with the version).

The cache is a valuable diagnostic tool. If a ping to 192.168.1.30 fails and the entry is FAILED or incomplete, the problem is at layer 2: the device is off, a cable is unplugged or the VLAN is wrong. If the entry has a valid MAC but the ping still fails, the device is reachable and a local firewall is probably blocking ICMP messages.

Gratuitous ARP

A gratuitous ARP is a message nobody asked for: a device announces its own IP–MAC mapping in broadcast, putting its own IP address as both sender and target. It is used in three situations:

  • at start-up or when the IP address changes, to update the caches of the other devices;
  • to detect a duplicate address: RFC 5227 describes the ARP “probes” a system sends before using an address; if anyone replies, the address is already taken;
  • during failover: in high-availability setups, for example two firewalls sharing a virtual address (CARP or VRRP), the unit that becomes active announces the address with a gratuitous ARP, so that clients and switches update their tables and caches at once.

ARP spoofing and man-in-the-middle

ARP was designed for trusted networks and has no authentication at all: a system accepts a reply without being able to check who sent it, and many systems even update their cache with replies they never asked for. A malicious device on the same network can therefore send forged replies, for example “192.168.1.1 is at 00:00:5e:00:53:0c”, which is its own MAC. This is ARP spoofing (or ARP poisoning).

If the attacker poisons both the PC's cache and the gateway's, all traffic between the two passes through it: a man-in-the-middle attack. It can read unencrypted data, change it or simply drop it. A device misconfigured with the gateway's address produces the same effect, without any malice.

ARP spoofing: traffic passes through the attacker The intended path goes straight from PC A, 192.168.1.10, to the gateway 192.168.1.1. After forged ARP replies from PC C, A's cache maps 192.168.1.1 to C's MAC and the gateway's cache maps 192.168.1.10 to C's MAC: traffic goes from A to C and from C to the gateway. PC A192.168.1.10 Gateway192.168.1.1 PC C · attacker…:0c intended path diverted traffic forwarded to the gateway A's cache: 192.168.1.1 → 00:00:5e:00:53:0c (forged) Gateway's cache: 192.168.1.10 → 00:00:5e:00:53:0c (forged)
Figure 4 — Simplified diagram. Forged ARP replies divert the traffic without A or the gateway noticing.

The main defences are these:

  • Dynamic ARP Inspection (DAI), available on many managed switches, sometimes under other names: the switch checks the ARP messages arriving on untrusted ports and drops those that do not match the known IP–MAC bindings, usually taken from DHCP snooping, which records the addresses handed out by the legitimate DHCP server.
  • Segmentation: an attacker can only poison the caches of its own local network. Separating guests, IoT devices and offices into different VLANs, with a firewall in between, greatly reduces the reach of an attack.
  • Access control: port security and IEEE 802.1X authentication limit who can connect to the network.
  • Encryption: with HTTPS, SSH and VPNs a man-in-the-middle only sees encrypted data and cannot alter it without the client noticing.
  • Static entries for a few critical addresses, such as the gateway on servers: they protect, but must be updated by hand every time hardware is replaced.

An intrusion detection system can also flag suspicious MAC changes for the same IP address.

What about IPv6?

IPv6 has no ARP. The same job is done by Neighbor Discovery (RFC 4861), based on ICMPv6: the device sends a Neighbor Solicitation message to a multicast address derived from the address being looked up (solicited-node), rather than to everyone, and receives a Neighbor Advertisement. The states that ip neigh also shows for IPv4, such as REACHABLE and STALE, come from this very protocol. Neighbor Discovery is exposed to attacks similar to spoofing too, and managed switches offer similar protections.

Common mistakes

  • A stale cache after replacing hardware. The router or firewall is replaced and keeps the address 192.168.1.1, but the new unit has a different MAC. Devices that still hold the old entry send frames to a MAC that no longer exists and cannot get online until the entry expires. The new unit usually sends a gratuitous ARP at start-up; if the problem persists, clear the clients' cache (or let it expire) and restart the network interface.
  • Duplicate IP address. Two devices with the same address both answer the requests: the other devices' caches flip between two MACs and the connection works intermittently. Windows reports the conflict, but not always. The most frequent causes and the remedies are described in the article on IP address conflicts.
  • Forgotten static entries. A static entry added years ago still points to a MAC that is no longer there: the device seems unreachable from that one computer only.
  • Wrong subnet mask. With a mask that is too wide, the PC believes an external destination is on its own network and looks it up with ARP instead of going through the gateway: the request goes unanswered.
  • Mixing up the layers when troubleshooting. Firewall rules filter IP packets, not the ARP messages within the same network. If the ARP entry is present but traffic does not get through, the problem lies higher up: addressing, routing or rules.

Practical conclusions

  • Remember the rule: on the same network ARP looks up the destination's MAC, off the subnet it looks up the gateway's.
  • When a device is unreachable, check the cache with arp -a or ip neigh: an incomplete entry points to a layer 2 problem.
  • After replacing a router, a firewall or a network card, expect the caches to need updating: clear them on the clients or wait for them to expire.
  • Avoid duplicate addresses: keep static addresses outside the DHCP range and write them down.
  • In business networks, enable DHCP snooping and Dynamic ARP Inspection on managed switches and separate devices into VLANs.

Readers who want to go further into how IP addressing, switching and local network security fit together will find these topics developed step by step in the Academy's books and video courses.

The video

ARP: How a PC Finds Another Device's MAC Address — Animation without voice-over, with on-screen text in English and sound effects.

Technical sources

  • RFC 826 — An Ethernet Address Resolution Protocol — Definition of ARP: Ethernet type 0x0806, message fields (hardware and protocol type, lengths, operation code, sender and target addresses), broadcast request, reply sent straight to the requester and update of the target's table.
  • RFC 1122 e RFC 5227 — Requirements for Internet Hosts; IPv4 Address Conflict Detection — Management and validation of the ARP cache in hosts; ARP probes and announcements to detect duplicate addresses before use.
  • RFC 4861 — Neighbor Discovery for IP version 6 — In IPv6, address resolution uses Neighbor Solicitation and Neighbor Advertisement (ICMPv6) to the solicited-node multicast address; REACHABLE, STALE and the other states.
  • Documentazione dei sistemi operativi — arp (Windows) e ip-neighbour (Linux, iproute2) — Viewing and clearing the ARP cache; states of the neighbour table entries. Entry lifetimes depend on the system and its version.
  • Documentazione dei produttori di switch gestiti — DHCP snooping e Dynamic ARP Inspection — Checking ARP messages on untrusted ports against the IP–MAC bindings recorded by DHCP snooping; names and options vary by vendor.
  • RFC 7042, RFC 1918 e RFC 5737 — Addresses used in the examples: MAC addresses 00:00:5e:00:53:xx reserved for documentation, the private network 192.168.1.0/24 and the documentation address 203.0.113.10.

Standards and official documentation available from the respective organisations.

OPNsense® is a registered trademark. Alba Technology does not represent the OPNsense project.