Sub topic 7
Rewriting the Layer 2 frame: ARP and neighbor discovery
This chapter assumes you know what an IP address and a MAC address are, and that a router has one interface in each network it connects. Earlier chapters covered how longest prefix match picks a route and a next hop. Now the router must actually put the packet on the wire toward that next hop.
Why the frame must be rewritten
An IP packet travels inside an Ethernet frame. That frame is only valid on one link. The router strips the incoming frame, makes its routing decision, and builds a new frame for the outgoing link.
The IP source and destination addresses stay the same from end to end (ignoring NAT). The Layer 2 addresses change at every hop:
- The new source MAC is the MAC of the router's outgoing interface.
- The new destination MAC is the MAC of the next hop, or of the destination host if it is directly connected.
The router must therefore know the MAC address that belongs to an IP address on the outgoing link.
ARP for IPv4
The Address Resolution Protocol (ARP) maps an IPv4 address to a MAC address on the same link. The router broadcasts a request to ff:ff:ff:ff:ff:ff asking who owns the next-hop IP. The owner replies directly to the router with its MAC address.
The router stores the answer in an ARP cache, also called a neighbor table, for a limited time. Later packets to the same next hop skip the request. While a lookup is pending, the router usually queues or drops the first packet, which is why the first ping to a new host often shows a delay or a loss.
Neighbor discovery for IPv6
IPv6 has no ARP. It uses Neighbor Discovery (ND), carried in ICMPv6. The router sends a Neighbor Solicitation to a multicast address derived from the target IP, and the owner answers with a Neighbor Advertisement containing its MAC. Only hosts whose address maps to that multicast group receive the request, so the whole link is not interrupted.
Inspecting the neighbor table
On Linux, the same command covers both IP versions:
# Show learned IPv4 and IPv6 neighbors and their state
ip neigh show
# Example output line:
# 192.0.2.2 dev eth0 lladdr aa:bb:cc:00:00:02 REACHABLECommon states are REACHABLE (recently confirmed), STALE (old, will be rechecked on use), and FAILED (no answer received).
Common errors
- Next hop not on the connected network. A route whose next hop is not reachable on a connected link cannot be resolved, so the router cannot build a frame.
FAILEDorINCOMPLETEentries. The next hop did not answer. Check cabling, VLAN membership, and that the next hop has the IP you expect.- Duplicate IP addresses. Two devices answer the same ARP request, and traffic flips between them.
- Wrong subnet mask on a host. The host ARPs for a remote address instead of sending to its gateway, so no one replies.
Exercise
A router forwards a packet to a destination on a remote network through next hop 192.0.2.2. Which IP address does it send the ARP request for, and which MAC address ends up as the destination in the new frame?
Show answer
It sends the ARP request for 192.0.2.2, the next hop, not the final destination. The destination MAC in the new frame is the MAC address in the ARP reply from 192.0.2.2. The IP destination in the packet is unchanged.