Sub topic 11
What changes and what stays the same at each router
This chapter assumes you know the Ethernet, IPv4 and TCP headers from the earlier chapters, and that ARP maps an IPv4 address to a MAC address on the local link. Here you will see which header fields a router leaves alone and which it rewrites.
The rule of thumb
Each layer has its own scope:
- Link layer (Ethernet): covers one hop only. Every hop gets a new frame.
- Network layer (IP): covers the whole path. The packet is the same packet from sender to receiver, with small edits.
- Transport layer and data (TCP or UDP header and payload): covers the two end hosts. Routers forward them without reading or changing them.
A router does not forward the frame it received. It decapsulates the frame, makes a routing decision from the IP header, and builds a new frame for the next link.
Step by step through a router
Suppose Host A sends a packet to Host B through two routers. At each router:
- The router receives a frame whose destination MAC is its own interface.
- It checks the frame check sequence, discards the Ethernet header and trailer, and keeps the IP packet.
- It looks up the destination IP address in its routing table to find the next hop and the outgoing interface.
- It decrements the TTL by 1 and recomputes the IPv4 header checksum.
- It resolves the next hop's MAC address, usually with ARP, and wraps the packet in a new Ethernet frame.
Field by field
| Field | Layer | At each router |
|---|---|---|
| Source MAC | Link | Changes to the router's outgoing interface |
| Destination MAC | Link | Changes to the next hop's MAC |
| Frame check sequence | Link | Recomputed for the new frame |
| Source IP | Network | Stays the same |
| Destination IP | Network | Stays the same |
| TTL | Network | Decreases by 1 |
| Header checksum | Network | Recomputed because TTL changed |
| Ports, sequence numbers | Transport | Stay the same |
| Application data | Application | Stays the same |
The last hop is a special case. R2 sends the frame to Host B's own MAC address, because B is on its local network. The destination IP was Host B's address from the start.
Why TTL exists
If routing tables contain a loop, a packet would circulate forever. The TTL (time to live) field limits this. When a router decrements TTL to 0, it drops the packet and sends an ICMP Time Exceeded message to the source. The traceroute tool relies on this behavior. It sends packets with TTL 1, 2, 3 and so on, and each router along the path reveals itself when it reports the expired packet.
Common errors
- Treating the destination MAC as end to end. In a capture, the destination MAC of a packet addressed to a server across the internet is your default gateway's MAC, not the server's.
- Expecting the IP addresses to be constant behind NAT. A NAT (network address translation) device rewrites the source IP, and usually the source port, so that a private address can use a public one. It must also fix the IP and TCP checksums. NAT is the main exception to the rule that IP addresses stay the same.
- Forgetting the checksum. An edit to any IP header field, including TTL, invalidates the header checksum. A router that skipped the update would produce packets the next hop discards.
- Assuming the link is identical on every hop. The incoming link might be Ethernet and the outgoing link something else, such as a different MTU or a different link technology. This is why the router builds a new frame instead of copying the old one.
Exercise
You capture a packet on Host A's interface. The destination IP is 203.0.113.5, and the destination MAC is the one belonging to your default gateway. When the packet arrives at 203.0.113.5, which of these fields will have the same value: destination MAC, destination IP, TTL, destination port? Assume no NAT.
Show answer
The destination IP and the destination port will be unchanged. The destination MAC is rewritten at every hop, and TTL is decremented at every router. The MAC on arrival is the receiving host's own address.