2024-06-08
traceroute
traceroute
is a command-line utility that reveals the path packets take to reach a destination host. It achieves this by sending packets with increasing Time To Live (TTL) values. Each router along the path decrements the TTL; when it reaches zero, the router sends an ICMP “Time exceeded” message back to the sender. traceroute
uses these responses to identify the routers along the path.
Basic Usage:
The most basic usage is straightforward:
traceroute google.com
This command will trace the route to google.com. The output will display a list of hops, their IP addresses, and the round-trip time (RTT) for each hop. You’ll see something like this (results will vary based on your network):
traceroute to google.com (172.217.160.142), 30 hops max, 60 byte packets
1 <your router's IP> (your router's name if configured) 0.504 ms 0.492 ms 0.488 ms
2 <ISP router 1 IP> <ISP router 1 name if configured> 1.234 ms 1.123 ms 1.012 ms
3 ... and so on ...
30 * * *
An asterisk (*) indicates a hop that didn’t respond.
Advanced Options:
traceroute
offers many useful options:
-f <first_hop>
: Specifies the first hop TTL. Useful to skip initial hops on your local network. For example: traceroute -f 5 google.com
starts at TTL 5.-m <max_hops>
: Sets the maximum number of hops to trace. The default is typically 30. Useful for limiting the trace depth to avoid long waits. For example: traceroute -m 15 google.com
-I
: Uses ICMP ECHO requests instead of UDP. This can sometimes improve results, especially when UDP is blocked.-p <port>
: Specifies the UDP port to use (if not using ICMP). This helps diagnose port-specific issues.-q <nqueries>
: Specifies the number of probes sent to each hop. The default is usually 3. Increasing this can improve the accuracy of RTT measurements. For example: traceroute -q 5 google.com
Example using Multiple Options:
traceroute -f 5 -m 20 -q 5 -I www.example.org
mtr
– An Enhanced traceroute
mtr
(my traceroute) combines the functionalities of traceroute
and ping
. It provides a more user-friendly output, displaying hop information, packet loss, and RTT statistics in a table format. This makes it easier to identify problematic hops.
Basic mtr
Usage:
mtr google.com
The output is dynamic, constantly updating as it sends probes. You’ll see columns for hop number, hostname, IP address, loss percentage, and RTT statistics (minimum, average, maximum, and standard deviation). This offers a far richer and more insightful view of network performance than traceroute
alone.
mtr
Options:
mtr
also supports a range of options, including:
-c <count>
: Specifies the number of probes to send before stopping.-r <report_interval>
: Sets the interval (in seconds) at which a report is displayed.-w <report_width>
: Adjusts the width of the report.-v
: Enables verbose output.Example using mtr
options:
mtr -c 10 -r 2 -w 80 google.com
This will send 10 probes, display a report every 2 seconds, and use a report width of 80 characters.
These commands are indispensable tools for diagnosing network connectivity problems. Their ability to pinpoint specific hops causing delays or packet loss is essential for troubleshooting network issues effectively. Mastering their usage enhances your ability to resolve network-related challenges within a Linux environment.