Let us follow a packet from your computer, 192.168.1.50, to a web server at 203.0.113.10.
Local or remote?
Your system first consults its routing table. If the destination is on a connected network, it sends straight to that host. If not, it picks a gateway.
$ ip route get 203.0.113.10
203.0.113.10 via 192.168.1.1 dev eth0 src 192.168.1.50 uid 1000
cacheFinding the next hop's MAC address
On Ethernet and Wi-Fi, a packet travels inside a frame addressed to a MAC address. For IPv4, your machine uses ARP to ask: who has 192.168.1.1? The answer is cached in the neighbour table:
$ ip neigh
192.168.1.1 dev eth0 lladdr 52:54:00:12:34:56 REACHABLEThe state may also be STALE or similar, which is normal. IPv6 uses Neighbor Discovery in place of ARP.
Note that the frame goes to the router's MAC address, while the IP destination is still the web server.
What a router does
Each router along the way:
- Receives the frame and takes out the IP packet.
- Lowers the TTL (time to live) by one. In IPv6 this field is called the hop limit.
- Looks up the destination in its own routing table.
- Builds a new frame for the next link and sends it.
The MAC addresses change on every hop. The source and destination IP addresses normally stay the same, with one common exception: NAT. Your home router usually replaces your private source address with its public one.
If the TTL reaches zero, the router drops the packet and usually sends back an ICMP "time exceeded" message. This stops packets from looping forever.
Seeing the hops
traceroute sends probes with TTL 1, then 2, then 3, so each router in turn reveals itself. It may need installing. tracepath, from iputils, is a similar tool that needs no root.
$ traceroute -n 203.0.113.10
traceroute to 203.0.113.10 (203.0.113.10), 30 hops max, 60 byte packets
1 192.168.1.1 1.214 ms 1.032 ms 1.108 ms
2 198.51.100.1 9.402 ms 9.117 ms 9.826 ms
3 * * *
4 203.0.113.10 21.305 ms 21.041 ms 21.633 ms* * * means no reply arrived in time. The router may simply not answer, so it does not prove the path is broken.
The reply from the server is routed independently, and may take a different path back. A working connection needs both directions.
The networking basics guide explains the layers behind frames and packets.
Try it
Run ip route get 203.0.113.10, then ip neigh and find your gateway's MAC address. If you have tracepath or traceroute, trace a host you are allowed to test and count the hops.
Check your understanding
The Path of a Packet
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.