Skip to main content

Understanding the `traceroute` Command in Linux

The traceroute command is a diagnostic utility that displays the path a packet takes to reach a network host or device, showcasing the transit delays of packets across an Internet Protocol (IP) network. It's an invaluable tool for understanding network issues and the topology of a network path.

Basics of the traceroute Command

The principle behind traceroute is simple: it sends packets to a destination, then analyzes the responses to determine the hops taken to reach said destination.

Syntax:

traceroute [OPTIONS] destination

Using the traceroute Command and Combining Options

Default Use: Tracing the route to a domain:

traceroute example.com

This command provides a step-by-step breakdown of the entire path taken from the source machine to example.com, noting any delays at each hop.

Using -I to Use ICMP ECHO for Probing:

traceroute -I example.com

By default, traceroute uses UDP datagrams to elicit an ICMP response from intermediate gateways. The -I option makes traceroute use ICMP ECHO requests instead.

Sample traceroute Output

Here's an example output of a traceroute command:

traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) 1.043 ms 1.021 ms 1.000 ms
2 10.10.10.1 (10.10.10.1) 10.431 ms 10.415 ms 10.396 ms
3 ... (skipping several hops for brevity)
10 93.184.216.34 (93.184.216.34) 24.052 ms 24.041 ms 24.023 ms

Reading the Output:

  • Each line represents a hop in the journey to the destination.

  • The IP address (and sometimes the domain name) of the hop is shown, followed by three round-trip time measurements (in milliseconds). These timings can help identify a bottleneck or problematic hop.

  • Sometimes, you might see * * *, indicating that the response was not received from that particular hop within the timeout period.

Key traceroute Options

OptionShorthandDescription
--type-TUse TCP SYN for probes.
--icmp-IUse ICMP ECHO for probes.
--queries-qNumber of probes per ttl (default is 3).
--max-hops-mSet the max TTL value, which essentially limits the number of hops. The default is 30.
--port-pSet the destination port to use. It is either initial udp port value for default method or initial seq for icmp.
--help-hDisplay help message.

Conclusion

traceroute is a vital tool in understanding network paths and potential bottlenecks or issues in reaching a particular destination. However, note that some devices are configured not to respond to ICMP requests or might rate-limit such replies, leading to partial or misleading outputs. As always, understanding the tool and the context in which it operates is essential for correct interpretation.

What Can You Do Next 🙏😊

If you liked the article, consider subscribing to Cloudaffle, my YouTube Channel, where I keep posting in-depth tutorials and all edutainment stuff for software developers.

YouTube @cloudaffle