Traceroute is a vital tool for diagnosing network issues. But it doesn't work by asking a server for its path; it works by tricking every router in between to talk back.
The TTL Trick
Every IP packet has a Time-To-Live (TTL). Every router subtracts 1. If it hits 0, the router drops the packet and sends an ICMP Time Exceeded message to the sender.
The Step-by-Step Scan
- Traceroute sends a packet with TTL=1. The first router drops it. Now we have Hop 1.
- Next, it sends one with TTL=2. The second router drops it. Now we have Hop 2.
- This continues until the destination is reached.
By measuring the time it takes for these "errors" to return, traceroute calculates the latency for every single hop across the internet.