What is a traceroute?
Traceroute is a tool used to diagnose problems in a network path. Traceroute is used to understand the path IP packets are taking from one computer (source IP address) to another (destination IP address). The command traceroute (on Linux or macOS) or tracert (on Windows) makes it possible to understand:
- The path your packets are taking (including the IP addresses of each router)
- The RTT* between the source and each hop, or router the packets pass through, in the network path
*Round-trip time (RTT) is the amount of time it takes for data to get to and from a certain point on a network.
Here is an example traceroute to 220.127.116.11. The lines with asterisks (* * *) represent hops from which packets were not returned; this can happen when routers are configured to ignore traceroute packets. The millisecond times in each line are the roundtrip times from the source to that hop for each packet (traceroute sends three packets at a time to verify the results).
|traceroute to 18.104.22.168 (22.214.171.124), 64 hops max, 52 byte packets|
|1 myrouter (192.168.47.1) 2.755 ms 1.452 ms 1.325 ms|
|2 * * *|
|3 126.96.36.199 (188.8.131.52) 18.159 ms 18.658 ms 15.091 ms|
|4 * * *|
|5 184.108.40.206 (220.127.116.11) 30.453 ms 50.242 ms 24.342 ms|
|6 one.one.one.one (18.104.22.168) 29.000 ms 26.784 ms 26.017 ms|
What is a network path?
A network path refers to the sequence of networks a packet passes through in order to reach its destination.
The Internet is a massive collection of networks that connect to one another via routing. Most Internet endpoints — for example, a web browser trying to access a website and the server which hosts that website — are not part of the same network. This means that if said web browser sends a request to the website’s servers, the request will probably have to hop between several intermediary networks along the way.
How does traceroute work?
A traceroute tool sends packets to a destination IP and with a time-to-live (TTL) set to 1, so that the first router the packets reach will send back an error (“time exceeded”). When the error returns, the traceroute tool records the first router’s identity and round-trip time, increments the TTL, and sends new packets, repeating this process until either 1) the last packet reaches the destination IP or 2) two sets of packets are dropped.
By doing this, the tool enables you to understand the path your packets are taking and the roundtrip time to each hop, so you can troubleshoot packet loss and latency.
Traceroute relies on the ICMP (Internet Control Message Protocol) protocol. ICMP is a network layer protocol used for error testing. It has no associated transport protocol, running directly on the Internet Protocol (IP). When the TTL of a packet sent by the traceroute tool is exceeded, the router sends back an ICMP Type 11 (Time Exceeded Error) packet.
Outgoing packets (sent from the starting router) can use ICMP (default on MacOS and Linux operating systems) or UDP (default on Windows). Choosing a different protocol for outgoing traceroute packets is one way to get more complete results if routers along the network path are configured to filter out packets of a certain protocol.
What is My Traceroute (MTR)?
My Traceroute (MTR) is a tool that combines traceroute and ping, which is another common method for testing network connectivity and speed. In addition to the hops along the network path, MTR shows constantly updating information about the latency and packet loss along the route to the destination. This helps in troubleshooting network issues by allowing you to see what’s happening along the path in real-time.
MTR works by discovering the network path in a similar manner to traceroute, and then regularly sending packets to continue collecting information to provide an updated view into the network’s health and speed.
Like traceroute, MTR can use ICMP or UDP for outgoing packets but relies on ICMP for return (Type 11: Time Exceeded) packets.
How to read MTR
Below are three examples of how to read and draw conclusions from MTR output.
MTR #1: All clean
This example follows the network path between the starting router and Cloudflare’s 22.214.171.124 DNS server. The MTR output does not indicate any problems — it takes 7 hops to reach 126.96.36.199, and none of them indicate any packet loss.
MTR #2: Packet loss - or is there?
|Packet loss on path|
This example shows the network path between the starting router and 2400:cb00:36:1008::a29e:40e2, which is an IPv6 address. The output shows significant packet loss on all the Cogent hops. However, there is no packet loss on the last hop (21). This indicates that the network path is actually not problematic. What's happening is something often referred to as "Control Plane Policing.”
As discussed earlier, MTR works by sending out (as a default) ICMP Echo packets, with an incrementing TTL (Time-To-Live) per packet. When the TTL expires, a router will send back an ICMP Type 11 (Time Exceeded), indicating how many hops there are from point A to point B.
Many network operators (including Cloudflare) set arbitrary limits on the amount of ICMP packets that are allowed to reach the control plane of a router. (The control plane is the router's brain.) A packet that exceeds a router's TTL has to be processed by the control plane. To prevent the control plane from being overwhelmed by too many of these packets, a rate limit (or policer) is put in place, which is why we see all that loss on the intermediary hops, but not the final hop: the control plane rate limits for the routers on the intermediary hops were exceeded, so Type 11 packets were not sent back for the traceroute packets past those limits, but the packets were able to get through to the destination safely.
MTR #3: Actual packet loss
|Packet loss on return path|
This example shows the network path between the starting router and 188.8.131.52. The output shows packet loss on the last 2 hops.
Further MTR options
MTR has a lot of options. You can find more through the MTR help page: mtr --help
Some of the frequently used options are:
- TCP MTR: Instead of using ICMP packets, use TCP. You can optionally choose a destination port as well.
- UDP MTR: Use UDP instead of ICMP. This can be used to circumvent routers that are blocking ICMP packets, or for the purpose of testing a specific port.
- Show IPs: Shows IP addresses next to the records for each hop. This makes it easier to report issues upstream.
- AS Lookup: Shows the AS number in the MTR.