ARP and NDP

On this page

If you can ping the same subnet but cannot reach a remote destination, first look at the next hop selected by routing, then examine the neighbor resolution for that next hop. ARP/NDP solves adjacency problems on the current link; it does not find the destination location in the internet. If the cache already has a valid mapping, or if it is a point-to-point link or uses other adjacency mechanisms, there may be no need to send resolution requests each time.

QuestionEntry in this articleDo not confuse with
Should ARP ask the gateway or the server?Routing and resolution orderFinal IP vs. Next-hop IP
Why is a 28 B ARP packet captured as 42/60 B?Packet byte accountingProtocol, Ethernet header, padding, and FCS
Must STALE entries be cleared?Neighbor statesValid mappings and recent reachability proofs
How does IPv6 direct neighbor discovery?NS/NA and multicastAddress resolution, reachability probes, and DAD
How do RAs affect addresses and default routes?AutoconfigurationPrefix L/A flags, address lifetimes, router lifetimes
Do encrypted tunnels solve spoofing?Security boundariesAuthentication, forwarding, and availability

Starting from a cross-subnet transmission

Assume A is 192.0.2.10/24, with a default gateway of 192.0.2.1, and it wants to access 198.51.100.20. The routing query selects the gateway as the next hop, and A queries the neighbor table of its interface; only when there is no mapping does it resolve the MAC address of 192.0.2.1, rather than broadcasting to the remote 198.51.100.20.

Select the next hop first, then resolve its MAC: Cross-subnet does not directly ARP the remote end Host A 192.0.2.10/24 Local Link Gateway 192.0.2.1 ARP Broadcast: Who has 192.0.2.1? ARP Reply: Gateway IP corresponds to Gateway MAC IP destination remains 198.51.100.20, Layer 2 destination is Gateway MAC The first request propagates within the local broadcast domain; only the relevant gateway is shown in the diagram; neighbor cache hits can skip the resolution interaction.

The interface is also part of the neighbor context: the same IPv4 address may appear in different VLANs or network namespaces, so you cannot describe all system states with a single global "IP→MAC dictionary". Routing errors, VLAN disconnection, or incorrect interface selection can all manifest as neighbor resolution failures.

ARP Packet and Minimum Frame Length

IPv4 ARP on Ethernet uses EtherType 0x0806 and is carried directly in Ethernet, bypassing the IPv4 header. Its generic fields allow different address lengths; the common Ethernet/IPv4 combination is as follows. RFC 826

FieldBytesValue in this example
Hardware Type / Protocol Type2 + 21 / 0x0800
Hardware Length / Protocol Length1 + 16 / 4
Operation21 Request, 2 Reply
Sender Hardware / Protocol Address6 + 4Sender MAC / IPv4
Target Hardware / Protocol Address6 + 4Target MAC / IPv4

The total is 28 B. Adding the untagged Ethernet header of 14 B results in only 42 B; another 18 B of padding is needed to reach 60 B (excluding FCS), and finally adding 4 B for FCS results in 64 B. The 46 B minimum Ethernet payload consists of 28 B of ARP and 18 B of padding; Ethernet headers and FCS are outside that payload. Whether padding and FCS are visible during packet capture depends on the location and driver.

The initial resolution request is usually sent with a broadcast MAC address, as the target hardware address is unknown; common implementations fill it with zeros, but this is not the Ethernet destination address used to determine the broadcast scope. Normal replies are usually unicast, and there are different usage forms such as announcements, so you cannot fix the direction of all ARP requests/replies.

Neighbor Table: Having a MAC and being confirmed reachable are two different things

Linux incorporates IPv4 ARP and IPv6 neighbor behavior into a generic neighbor framework. INCOMPLETE indicates that resolution is in progress, and packets to be sent can wait in a limited queue; REACHABLE indicates that a recent reachability confirmation was received; STALE retains the mapping but the confirmation is old, meaning the entry is not "broken".

Neighbor states describe mappings and reachability: STALE can still send data first INCOMPLETE Resolving, may be queued REACHABLE Recent reachability confirmation STALE Mapping exists, confirmation is old DELAY Send, then await confirmation PROBE / FAILED Active probe / Resolution failed Valid confirmation Confirmation becomes old Use again No confirmation during wait period Confirmation → REACHABLE Common path illustration, not a complete state diagram; retries/aging are configurable, FAILED does not mean the object is immediately deleted from the neighbor table.

When using a STALE entry, you can usually send packets using the existing MAC first, then enter DELAY to wait for confirmation from upper layers or other sources; if necessary, switch to PROBE for active probing. If all probes are exhausted, it can enter FAILED, but entry recycling is handled by subsequent lifetime/garbage collection, and it is not guaranteed to disappear immediately from ip neigh. Whether a received packet constitutes a reachability proof also depends on the type and state; not every ARP/NA directly sets REACHABLE.

This article verified the STALE→DELAY, wait-for-confirmation, and probe-failure paths against the Linux 7.2 kernel net/core/neighbour.c. In practice, there are also special states such as permanent and externally managed entries; the diagram only shows common paths; when REACHABLE expires, it may also combine recent usage to directly enter states like DELAY, so do not treat the diagram as a line-by-line implementation.

base_reachable_time_ms is the baseline for reachability time, with actual reachability time undergoing randomization and other processing; delay_first_probe_time, retrans_time_ms, ucast_solicit, and mcast_solicit affect waiting and probing respectively. gc_stale_time is related to the eligibility of unused entries for recycling, not a fixed survival countdown for every STALE entry. Configuration also needs to distinguish between default templates and specific interfaces; it is not advisable to "tune" according to fixed 30/60 seconds without looking at the actual state.

Why probe when the MAC is already known?

Separate mapping existence, transmitted data and freshness of reachability evidence. Send from STALE, then confirm, or exhaust probes: failure cannot recall already-sent data. Clearing the mapping makes subsequent data wait for resolution.

Preparing the visual
Why probe when the MAC is already known?

STALE retains a mapping and can send before waiting for confirmation. Unknown resolution queues data; probe failure is distinct from immediate entry deletion.

IPv4 Conflict Detection and Address Announcement are different

ARP Probe in RFC 5227 detects conflicts when a candidate address is not yet in use, with the sender IPv4 as 0.0.0.0 and the target IPv4 as the candidate address; this avoids writing an unconfirmed mapping into other hosts' caches first. ARP Announcement declares an address that is currently in use, with both sender and target IPv4 being the same. Writing both as "send a gratuitous ARP and wait for a reply" would miss simultaneous detection and conflict judgment. RFC 5227: IPv4 Address Conflict Detection

Announcements during failover help update neighbor mappings, and switching devices can learn the ingress from the source MAC; these are different tables. Policy filtering, static entries, unchanged MAC, or unconverged forwarding tables can all affect the failover result, so you cannot promise zero packet loss immediately after sending an announcement.

Proxy ARP is when a device answers on behalf of the target and provides its own MAC, subsequently forwarding on its behalf. The prerequisite is that the sending host determines based on routing/link that it indeed needs to resolve that target; if it has already determined that the target is via the default gateway, it will usually ask the gateway. Proxies can be used in explicitly designed access scenarios, but they may also mask incorrect on-link judgments; their role should be explained in conjunction with routing and policies.

NDP Messages: Correct numbering and validation rules

NDP is carried by ICMPv6. Basic messages include RS 133, RA 134, NS 135, NA 136, and Redirect 137; the Code for these messages is always 0. The common header only includes general parts like Type, Code, and Checksum; subsequent fixed fields vary by message type and cannot be uniformly drawn as four reserved bytes. The checksum includes the IPv6 pseudo-header; receiving validation also checks conditions like Hop Limit=255 to limit spoofed packets forwarded across routers, but it does not authenticate the local sender. RFC 4861: Message Format and Validation

Common ND Option TypeMeaning
1Source Link-Layer Address
2Target Link-Layer Address
3Prefix Information
4Redirected Header
5MTU

The Length of these options is in units of 8 B and includes the type and length fields; zero length is invalid. Ethernet link-layer address options are often 8 B; you cannot call Type 1 both source and target address, and then shift the subsequent numbering as a whole.

NS/NA: Multicast narrows the scope, but one group can correspond to multiple addresses

Initial resolution usually sends NS to the target's solicited-node multicast address. This address is ff02::1:ff00:0/104 plus the lowest 24 bits of the target IPv6; Ethernet IPv6 multicast MAC uses 33:33 plus the lowest 32 bits of the IPv6 multicast address. Therefore, the target 2001:db8::1234:5678 corresponds to ff02::1:ff34:5678 and 33:33:ff:34:56:78. RFC 2464: IPv6 Multicast to Ethernet Mapping

Multiple IPv6 addresses may share the lowest 24 bits, thus sharing the group; the receiver still needs to check the full Target Address of the NS and cannot judge "it's looking for me" solely based on the Ethernet destination MAC. Reachability probes for known neighbors may also use unicast NS; NS is not just a type of multicast inquiry.

Normal solicited NA can be returned unicast, carrying the target link-layer address and R/S/O flags. R indicates router role, S indicates the corresponding solicited reachability confirmation semantics, and O affects existing mapping updates; the Solicited flag for multicast NA cannot be set to 1 just because "it is also a response". Cache updates must be executed based on the original state and flags. RFC 4861: Address Resolution and NA Processing

DAD: How to ask if there is a conflict when you don't have an address yet

In normal DAD, the candidate address is tentative; the NS sent has a source of ::, Target is the candidate address, and it does not carry a Source Link-Layer Address option. The owner of an existing address can reply with the corresponding NA; two nodes probing the same address simultaneously may also discover a conflict by receiving each other's NS, so you cannot just count NAs or assume that only the "second one" fails.

The address is only enabled according to the protocol flow if no conflict is observed, but packet loss, filtering, and link separation mean that DAD is not an absolute proof of uniqueness. The number of enablements, applicable exceptions, optimized DAD, and OS policies must be distinguished; you cannot prescribe the same process for all types of addresses. RFC 4862: DAD

Hosts can request router information via RS, and routers can also send RAs periodically; the RA source is usually the router's link-local address. The response destination needs to be selected based on conditions such as the RS source; an RS with a source of :: cannot require the RA to be unicast to an unspecified address.

The L in Prefix Information indicates the on-link information of the prefix, and A indicates whether it can be used for autonomous address configuration; the two are independent. Having an address/prefix length should not be unconditionally interpreted as all matching addresses being directly reachable; hosts must follow the on-link information and routing selection. RFC 5942: IPv6 Subnet Model

When the Preferred Lifetime of an address expires, it enters deprecated, usually avoiding selection for new communications, but existing communications can continue as long as it is still valid; after the Valid Lifetime expires, the address is no longer valid. The RA Router Lifetime controls the period during which this router serves as a default route candidate; setting it to 0 does not simultaneously revoke all prefixes and addresses. Specific lifetime updates have protocol rules; you cannot set them all to fixed days uniformly.

The IID of SLAAC can use appropriate stable opaque mechanisms or temporary address policies, and should not default to generating from the MAC. The temporary addresses in RFC 8981 change periodically, reducing the risk of association with specific addresses, but it does not hide all network identifiers, nor is it enabled by default on all Linux installations; system configuration and address selection policies need to be checked in practice. RFC 8981: Temporary Address Extensions

Do addresses and default routes expire together?

Lifetimes belong to different objects. At t70 an address may remain valid but deprecated while this RA’s default route has expired; clearing L does not clear A. Time observes one initial advertisement, while flags reconstruct that advertisement.

Preparing the visual
Do addresses and default routes expire together?

A and L are independent; preferred expiry deprecates, valid expiry invalidates. Router Lifetime separately controls default-router candidacy.

Security: Encryption protects content, not neighbor availability

The basic address declarations of ARP/NDP lack universal source authentication, and local link spoofing can affect mappings, routing, or address configuration. Access control, appropriate ARP inspection/binding, and RA protection must be designed in conjunction with trusted ingress and address sources; static neighbor entries can fix some mappings, but they bring maintenance burdens and cannot protect all link behaviors.

Properly authenticated TLS or encrypted tunnels can protect the content and integrity of the covered sessions, but attackers can still drop packets, block handshakes, or cause link unavailability. Therefore, "using WireGuard makes ARP spoofing invalid" is not true; confidentiality, identity, and availability should be judged separately.

Local packet and multicast mapping recalculation

import struct
from ipaddress import IPv4Address, IPv6Address

sha = bytes.fromhex('020000000001')
arp = struct.pack('!HHBBH', 1, 0x0800, 6, 4, 1)
arp += sha + IPv4Address('192.0.2.10').packed
arp += bytes(6) + IPv4Address('192.0.2.1').packed
assert len(arp) == 28
padding = max(0, 46-len(arp))
assert padding == 18 and 14+len(arp)+padding+4 == 64
assert struct.unpack('!H', arp[6:8])[0] == 1

target = IPv6Address('2001:db8::1234:5678')
solicited = IPv6Address(int(IPv6Address('ff02::1:ff00:0')) | (int(target)&0xffffff))
assert str(solicited) == 'ff02::1:ff34:5678'
mac = bytes.fromhex('3333') + solicited.packed[-4:]
assert mac.hex(':') == '33:33:ff:34:56:78'
assert bytes([1, 1]) + sha == bytes.fromhex('0101020000000001')
print('ARP fields/padding, request opcode, and IPv6 multicast mapping passed')

This only constructs bytes locally and recalculates; it does not send ARP/NS to the network, clear neighbor caches, or modify sysctl.

Continue reading