Sub topic 9
Why MAC addresses change at every router hop
This chapter assumes you know that a MAC address identifies an interface on a local network. It also assumes you know that an IP address identifies a host across networks, and that ARP maps an IPv4 address to a MAC address on the local link. You should be able to read hexadecimal.
Two addresses, two jobs
Every packet that crosses a routed network carries two kinds of address. They answer different questions.
- The IP address says who the packet is from and who it is finally for. It stays the same from the sender to the receiver.
- The MAC address says which interface on the current link should receive this frame. It is only meaningful on that one link.
A MAC address is not routable. A router does not forward a frame to another network. It receives a frame, removes the Ethernet header, reads the IP packet inside, decides where to send it, and builds a new frame for the next link.
What the sender does
Host A wants to reach host B on another network. A compares B's IP address with its own subnet and sees that B is not local. A sends the packet to its default gateway.
So A does not ARP for B. It ARPs for the gateway's IP address. The frame therefore has:
- Destination MAC: the gateway's MAC address.
- Destination IP: B's IP address.
The destination IP and the destination MAC point at different devices. This is normal, and it is the core of the chapter.
What each router does
At each hop, the router performs these steps:
- Accept the frame because the destination MAC is its own interface.
- Strip the Ethernet header and trailer.
- Look up the destination IP in its routing table and pick the next hop and outgoing interface.
- Decrement the TTL (IPv6: hop limit) and update the IP checksum (IPv4 only).
- Resolve the next hop's MAC address with ARP (or Neighbor Discovery).
- Build a new Ethernet frame. The source MAC is the router's outgoing interface. The destination MAC is the next hop.
On the last hop, the router finds that B is on a directly connected network. It ARPs for B's own IP address and uses B's MAC as the destination.
A worked example
The table lists the addresses in the packet on each link. The MAC values are made up for the example.
| Link | Source MAC | Destination MAC | Source IP | Destination IP |
|---|---|---|---|---|
| A to R1 | 02:00:00:00:00:0a | 02:00:00:00:01:01 | 10.0.1.10 | 10.0.3.20 |
| R1 to R2 | 02:00:00:00:01:02 | 02:00:00:00:02:01 | 10.0.1.10 | 10.0.3.20 |
| R2 to B | 02:00:00:00:02:02 | 02:00:00:00:00:0b | 10.0.1.10 | 10.0.3.20 |
Read down the two IP columns and nothing changes. Read down the two MAC columns and every value is different. Each frame is built fresh for its own link.
You can check this on a real machine. Find your gateway, then look at the neighbor table. You will see the gateway's MAC address there, even when you are browsing a server on the other side of the world.
# Which gateway does traffic to the internet use?
ip route show default
# The neighbor table holds the gateway's MAC, not the remote server's
ip neigh showCommon mistakes
- Expecting to see the remote server's MAC address. A host never learns it. ARP only works within the local broadcast domain.
- Thinking a switch changes the MAC addresses. A switch forwards the frame unchanged. Only a router (a layer 3 device) rewrites them.
- Forgetting that the gateway must be resolved first. If ARP for the gateway fails, off-network traffic fails even though the IP configuration looks correct.
Why the design works this way
Keeping MAC addresses local means the link layer needs no global knowledge. MAC addresses have no network structure, so a router could not summarize them into routes. IP addresses are hierarchical, so routers can aggregate them. Each layer does the job it suits.
Exercise
Host A (10.0.1.10) sends a packet to host B (10.0.3.20) through one router. On the frame that leaves A, whose MAC address is the destination, and which IP address is the destination?
Show answer
The destination MAC is the router's (default gateway's) interface MAC on A's network. The destination IP is B's address, 10.0.3.20. A resolved the gateway's MAC with ARP because B is not on A's subnet.
Exercise
A packet crosses four routers between sender and receiver. How many different Ethernet frames carry it, and what stays unchanged in all of them?
Show answer
Five frames, one per link (sender to router 1, three router-to-router links, and router 4 to the receiver). The source and destination IP addresses stay unchanged (apart from NAT), while the MAC addresses change on every link. The TTL is decremented at each router.