How to Use the Command 'mtr' (with Examples)

How to Use the Command 'mtr' (with Examples)

Matt’s Traceroute (mtr) is an essential diagnostic tool for network administrators, providing a combination of traceroute and ping functionalities. This tool helps diagnose network problems by displaying the route packets take to a specified destination, and measuring the delay and packet loss at each hop along the network path. Whether for preliminary diagnostics or comprehensive network troubleshooting, mtr offers valuable insights into network performance and reliability.

Use Case 1: Traceroute to a Host and Continuously Ping All Intermediary Hops

Code:

mtr example.com

Motivation: By running mtr on example.com, network administrators can monitor the connectivity to a specific domain in real-time, observing the flow of packets through various network nodes along the route. This continuous feedback is crucial for detecting intermittent connectivity issues or identifying specific hops experiencing packet loss or high latency.

Explanation: This command will initiate a traceroute to the host example.com, continuously sending packets to each intermediate hop on the path, displaying the number of packets sent, received, and lost, along with timing statistics.

Example Output:

Start: Tue Oct 10 12:34:56 2023
HOST: localhost                      Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. example.com                      0.0%    10    9.5   8.9   7.5  10.3  1.2

Use Case 2: Disable IP Address and Host Name Mapping

Code:

mtr --no-dns example.com

Motivation: When analyzing network behavior, sometimes you need faster results or information with less clutter. Disabling DNS resolution with --no-dns makes mtr execute faster since it doesn’t spend time resolving IP addresses into hostnames, providing a quicker overview of network paths in purely numerical form.

Explanation: The --no-dns option tells mtr not to resolve IP addresses to hostnames, thus displaying numerical IP addresses instead of potentially time-consuming name lookups.

Example Output:

Start: Tue Oct 10 12:36:02 2023
HOST: localhost                      Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. 192.168.0.1                      0.0%    10    3.1   2.9   2.1   4.0  0.6

Use Case 3: Generate Output After Pinging Each Hop 10 Times

Code:

mtr --report-wide example.com

Motivation: For network diagnostics that require a snapshot of performance metrics across the network path, you can use --report-wide. By sending exactly 10 pings per hop, this command produces a detailed report that can be used for documentation or further analysis.

Explanation: The --report-wide option tells mtr to run for a specified number of pings per hop (default 10) and then exit, providing a comprehensive report of network conditions.

Example Output:

HOST: localhost                      Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. 192.168.0.1                      0.0%    10    3.1   2.9   2.1   4.0  0.6
  2. example.com                      0.0%    10    9.5   8.9   7.5  10.3  1.2

Use Case 4: Force Use of IPv4 or IPv6

Code:

mtr -4 example.com

Motivation: In environments where dual-stack (both IPv4 and IPv6) networking is present, it may be necessary to specify the IP version to be used for routing. Using -4 or -6 ensures that mtr uses IPv4 or IPv6, respectively, facilitating focused diagnostics in a mixed protocol environment.

Explanation: The -4 option forces mtr to run using IPv4, ensuring that the results pertain explicitly to the IPv4 network infrastructure. Similarly, -6 could be used for IPv6 diagnostics.

Example Output:

Start: Tue Oct 10 12:39:50 2023
HOST: localhost                      Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. 192.168.0.1                      0.0%    10    3.1   2.9   2.1   4.0  0.6

Use Case 5: Wait for a Given Time Before Sending Another Packet to the Same Hop

Code:

mtr --interval 10 example.com

Motivation: Adjusting the interval between the probes can reduce network load during long monitoring sessions or when analyzing congested networks. By increasing the interval with --interval 10, you wait 10 seconds between sending each packet, minimizing the impact on the network and providing a broader time window for observables.

Explanation: The --interval 10 flag sets the delay between consecutive packets sent to a specific hop to 10 seconds, allowing for less intrusive, longer-term monitoring.

Example Output:

Start: Tue Oct 10 12:42:00 2023
HOST: localhost                      Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. 192.168.0.1                      0.0%    10    3.1   2.9   2.1   4.0  0.6

Use Case 6: Display the Autonomous System Number (ASN) for Each Hop

Code:

mtr --aslookup example.com

Motivation: Understanding the ASNs that traffic traverses can be crucial for ensuring compliance, understanding interconnections, or debugging routing issues. With --aslookup, mtr helps identify the network ownership of each hop in the path, providing deep insight into the architecture underlying Internet transport.

Explanation: The --aslookup option instructs mtr to perform a lookup for the Autonomous System Number associated with each IP address in the path, appending ASN information to the output.

Example Output:

HOST: localhost                      ASN    Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. 192.168.0.1                     AS1234   0.0%    10    3.1   2.9   2.1   4.0  0.6

Use Case 7: Display Both IP Address and Reverse DNS Name

Code:

mtr --show-ips example.com

Motivation: Presenting detailed information about each hop, including both IP addresses and their reverse DNS names, can assist in network diagnostics, providing context such as domains associated with specific IPs for easier identification and troubleshooting.

Explanation: The --show-ips option outputs both the IP address and the reverse DNS hostname for each hop, offering a more comprehensive view that highlights the associated names alongside the numerical addresses.

Example Output:

HOST: localhost                      Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. (192.168.0.1) [my-gateway.local] 0.0%    10    3.1   2.9   2.1   4.0  0.6

Conclusion

Each use case of the mtr command offers a unique perspective for network diagnostics, tailoring its versatile functionalities to meet various investigative needs. From continuous real-time tracking to in-depth static reporting, mtr provides the necessary tools to effectively diagnose and comprehend diverse network conditions, making it indispensable for network administrators and IT professionals.

Related Posts

How to use the command 'mogrify' (with examples)

How to use the command 'mogrify' (with examples)

The mogrify command is a powerful and versatile tool for modifying and transforming images.

Read More
How to use the command 'autorecon' (with examples)

How to use the command 'autorecon' (with examples)

AutoRecon is a sophisticated multi-threaded network reconnaissance tool designed to automate the enumeration of services on one or multiple targets.

Read More
How to Use the Command 'hledger balancesheet' (with Examples)

How to Use the Command 'hledger balancesheet' (with Examples)

The hledger balancesheet command is a component of the powerful hledger toolset, designed for personal and small-business accounting.

Read More