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

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

The ‘mtr’ command is a combined traceroute and ping tool developed by Matt Kimball. It provides a visual display of the network route taken by packets from your computer to a destination host, along with information about the round-trip time (RTT) for each hop. It is commonly used for network troubleshooting and monitoring purposes.

Use case 1: Traceroute to a host and continuously ping all intermediary hops

Code:

mtr example.com

Motivation: This use case helps in understanding the network route taken to reach the destination host, along with the response time of each hop. Continuous pinging of intermediary hops provides real-time statistics, helping to identify network or latency issues.

Explanation: By simply providing the target host (in this case, ’example.com’) as an argument to the ‘mtr’ command, it starts the traceroute and continuously pings each intermediate hop along the way.

Example output:

Start: Sun Nov 28 20:58:07 2021
HOST: YourComputer                  Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. router                            0.0%    10    0.5   0.4   0.3   0.6   0.1
  2. 10.10.10.1                        0.0%    10    2.5   2.8   2.4   3.4   0.3
  3. 192.168.1.1                       0.0%    10    1.2   1.5   1.1   1.8   0.2
  4. 203.0.113.1                       0.0%    10    3.6   3.8   3.4   4.3   0.3
  ...

Use case 2: Disable IP address and host name mapping

Code:

mtr --no-dns example.com

Motivation: Sometimes, during network troubleshooting, it may be helpful to disable IP address and host name mapping to simplify the output and focus solely on the network latency and packet loss.

Explanation: By adding the ‘–no-dns’ flag, the ‘mtr’ command skips the step of resolving IP addresses to host names, resulting in a simplified output without the host names.

Example output:

Start: Sun Nov 28 21:00:34 2021
HOST:                                 Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. 192.0.2.1                         0.0%    10    0.4   0.4   0.3   0.5   0.1
  2. 198.51.100.1                      0.0%    10    2.6   2.7   2.4   3.3   0.3
  3. 203.0.113.1                       0.0%    10    1.2   1.5   1.1   1.8   0.2
  4. 192.0.2.10                        0.0%    10    3.7   3.9   3.4   4.2   0.3
  ...

Use case 3: Generate output after pinging each hop 10 times

Code:

mtr --report-wide example.com

Motivation: Generating a wider report with multiple pings to each hop provides a more comprehensive view of network latency and packet loss. This can help identify intermittent issues that may not be apparent with fewer pings.

Explanation: The ‘–report-wide’ flag instructs the ‘mtr’ command to generate a wider report, with statistics based on the average of 10 pings for each hop.

Example output:

Start: Sun Nov 28 21:03:12 2021
HOST:                                 Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. 192.0.2.1                         0.0%    10    0.3   0.4   0.3   0.5   0.1
  2. 198.51.100.1                      0.0%    10    2.6   2.7   2.4   3.3   0.3
  3. 203.0.113.1                       0.0%    10    1.2   1.5   1.1   1.8   0.2
  4. 192.0.2.10                        0.0%    10    3.7   3.9   3.4   4.2   0.3
  ...

Use case 4: Force IP version (IPv4 or IPv6)

Code:

mtr -4 example.com

Motivation: In some scenarios, it may be necessary to specifically use either IPv4 or IPv6 for the traceroute and ping. This use case allows forcing the IP version.

Explanation: The ‘-4’ flag tells the ‘mtr’ command to force the use of IPv4. If you wanted to force the use of IPv6, you would use the ‘-6’ flag instead.

Example output:

Start: Sun Nov 28 21:05:41 2021
HOST:                                 Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. 192.0.2.1                         0.0%    10    0.4   0.4   0.3   0.5   0.1
  2. 198.51.100.1                      0.0%    10    2.6   2.7   2.4   3.3   0.3
  3. 203.0.113.1                       0.0%    10    1.2   1.5   1.1   1.8   0.2
  4. 192.0.2.10                        0.0%    10    3.7   3.9   3.4   4.2   0.3
  ...

Use case 5: Wait for a given time (in seconds) before sending another packet to the same hop

Code:

mtr --interval 10 example.com

Motivation: By specifying an interval between packets, it is possible to control the frequency at which pings are sent to each hop. This can help in scenarios where you want to reduce network traffic or increase the interval to avoid overwhelming hops that may have resource limitations.

Explanation: The ‘–interval’ flag followed by a number (in this case, ‘10’) specifies the time interval (in seconds) to wait before sending another packet to the same hop.

Example output:

Start: Sun Nov 28 21:08:08 2021
HOST:                                 Loss%   Snt   Last   Avg  Best  Wrst StDev
  1. 192.0.2.1                         0.0%    10    0.4   0.4   0.3   0.5   0.1
  2. 198.51.100.1                      0.0%    10    2.6   2.7   2.4   3.3   0.3
  3. 203.0.113.1                       0.0%    10    1.2   1.5   1.1   1.8   0.2
  4. 192.0.2.10                        0.0%    10    3.7   3.9   3.4   4.2   0.3
  ...

Use case 6: Display the Autonomous System Number (ASN) for each hop

Code:

mtr --aslookup example.com

Motivation: Autonomous System Numbers (ASNs) provide information about the network infrastructure and organizations responsible for each hop. This use case helps identify the ASNs associated with each hop, which can be useful for network administrators and troubleshooting.

Explanation: The ‘–aslookup’ flag instructs the ‘mtr’ command to display the Autonomous System Number (ASN) for each hop.

Example output:

Start: Sun Nov 28 21:10:35 2021
HOST:                                 Loss%   Snt   Last   Avg  Best  Wrst StDev ASN
  1. 192.0.2.1                         0.0%    10    0.4   0.4   0.3   0.5   0.1 AS12345
  2. 198.51.100.1                      0.0%    10    2.6   2.7   2.4   3.3   0.3 AS54321
  3. 203.0.113.1                       0.0%    10    1.2   1.5   1.1   1.8   0.2 AS67890
  4. 192.0.2.10                        0.0%    10    3.7   3.9   3.4   4.2   0.3 AS98765
  ...

Use case 7: Display both IP address and reverse DNS name

Code:

mtr --show-ips example.com

Motivation: Sometimes, it can be helpful to display both the IP address and reverse DNS name of each hop, providing additional context when analyzing the traceroute output.

Explanation: The ‘–show-ips’ flag enables the ‘mtr’ command to display both the IP address and reverse DNS name of each hop.

Example output:

Start: Sun Nov 28 21:13:00 2021
HOST:                                 Loss%   Snt   Last   Avg  Best  Wrst StDev IP
  1. 192.0.2.1                         0.0%    10    0.4   0.4   0.3   0.5   0.1 router.example.com (192.0.2.1)
  2. 198.51.100.1                      0.0%    10    2.6   2.7   2.4   3.3   0.3 hop1.example.com (198.51.100.1)
  3. 203.0.113.1                       0.0%    10    1.2   1.5   1.1   1.8   0.2 hop2.example.com (203.0.113.1) 
  4. 192.0.2.10                        0.0%    10    3.7   3.9   3.4   4.2   0.3 hop3.example.com (192.0.2.10)
  ...

Conclusion:

The ‘mtr’ command is a powerful network diagnostic tool that combines traceroute and ping functionality. With its various options, it provides valuable insights into network latency, packet loss, and intermediate hops. By understanding and utilizing the different use cases of the ‘mtr’ command, network administrators and individuals can effectively troubleshoot and monitor their network infrastructure.

Related Posts

Splitting a File into Pieces (with examples)

Splitting a File into Pieces (with examples)

Introduction The split command is a powerful tool for splitting a file into smaller pieces.

Read More
How to use the command iperf (with examples)

How to use the command iperf (with examples)

Iperf is a command-line tool used to measure the network bandwidth between computers.

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

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

The arecord command is a sound recorder for ALSA soundcard driver.

Read More