What is the mtr command?

Mtr (my traceroute) is a command-line network diagnostic tool that provides the functions of the ping and traceroute commands. It is a simple and cross-platform tool that outputs information about the entire route that network packets take from the host system to the specified destination system. The mtr command is superior to the traceroute command because it also outputs the response percentage and response times for all network hops between the two systems.

As a network administrator, you must know how to use the mtr command and the flags that you can use to customize the output in order to perform productive network diagnostics. This article explains the use of the mtr command in detail and provides examples to show you how to use specific flags with this command.

We have run the commands and procedures described in this article on an Ubuntu 18.04 and Ubuntu 20.04 LTS system.

Since mtr is a command-line program, we will use it in the Ubuntu command line, the terminal. You can open the terminal application using either the System Dash or the key combination Ctrl Alt t.

Usage of the Mtr Command

1. View traceroute report in real time

The mtr command is primarily used to display the traceroute report for a remote machine. All you have to do is enter the domain name or IP address of the remote system using the mtr command and the output will display the traceroute report in real-time. When you’re done viewing the report, you can exit the command with either q or the Ctrl C key combination.

Display Hostnames

The following syntax of the mtr command displays the hostnames in the traceroute report.

Syntax:

$ mtr [domainName/IP]

Example:

$ mtr google.com

How to use the Linux mtr (My Traceroute) command linux ubuntu

Display Numeric IP addresses

When you use the g flag with the mtr command, it displays the numeric IP addresses instead of the hostnames in the traceroute report.

Syntax:

$ mtr -g [domainName/IP]

Example:

$ mtr -g google.com

<img alt="traceroute with mtr" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-37.png6256b94ba79a2.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="161" loading="lazy" src="data:image/svg xml,” width=”738″>

Both hostnames and numeric IP addresses

When you use the b flag with the mtr command, it displays both the numeric IP addresses and the hostnames in the traceroute report.

Syntax:

$ mtr -b [domainName/IP]

Example:

$ mtr -b google.com

<img alt="Show hostnames and IP addresses" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-38.png6256b94be1a2f.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="165" loading="lazy" src="data:image/svg xml,” width=”736″>

2. Specify a limit for the number of pings

You can configure the mtr command to quit after printing the traceroute report for a specific number of pings. In the output, you can easily view the number of pings under the Snt column; when Snt reaches the number you specified in your command through the c flag, mtr will automatically exit.

Syntax:

$ mtr -c [n] “domainname/IP”

Example:

$ mtr -c 10 google.com

3. Enable Report Mode

Instead of printing the output of the mtr command on the screen, you can enable the report mode that will instead print the output in a text file. This way you can record the network analysis for later use and observation. All you need to do is enable the report mode through the r flag, specify a ping count for which you want to limit the report through the c flag, and also specify the report filename in which the report will be saved.

Syntax:

$ mtr -r -c [n] “domainname/IP” >”report-name”

Example:

$ mtr -r -c 10 google.com >mtr-report-google

The report is saved in the current user’s home folder by default. You can, however, specify a proper path for the report to be saved in.

<img alt="Report mode enabled in mtr command" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-39.png6256b94c1d3ce.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="165" loading="lazy" src="data:image/svg xml,” width=”895″>

Clear output in Report

Adding a w flag with the r flag will enable mtr to print a rather clear and more readable report for the traceroute.

Syntax:

$ mtrrw -c [n] “domainname/IP” >”report-name”

Example:

mtr -rw -c 10 google.com >mtr-report-google

4. Rearrange the output fields

When you see the output of the mtr report, you will observe that the columns are arranged in a specific default manner. The o flag enables you to re-arrange the output in a customized manner to make it more useful and productive.

Syntax:

$ mtr -o “[Output Format]” “domainname/IP”

The mtr manpage can help you with what options you have while customizing the mtr report columns.

Example:

$ mtr -o "LSDR NBAW JMXI" google.com

<img alt="Rearrange the output fields" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-40.png6256b94c3f969.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="155" loading="lazy" src="data:image/svg xml,” width=”734″>

5. Specify Time Interval between ICMP ECHO requests

Although the default time interval between each ICMP and ECHO request is 1 second in the mtr command, you can change it by using the i flag to specify a new time interval.

Syntax:

$ mtr -i [time-in-seconds] “domainName/IP”

Example:

$ mtr -i 10 google.com

6. Use TCP SYN packets or UDP datagrams

If you want to use the TCP SYN or the UDP datagrams for requesting mtr instead of the default ICMP ECHO requests, you can do so by using the tcp and udp flags respectively.

Syntax:

$ mtr –tcp “domainName/IP”

$ mtr –udp “domainName/IP”

Example:

$ mtr --tcp google.com
$ mtr --udp google.com

<img alt="Use TCP SYN packets or UDP datagrams" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-41.png6256b94c67884.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="304" loading="lazy" src="data:image/svg xml,” width=”738″>

7. Specify the maximum number of hops between the local system and the remote machine

You can customize the maximum number of hops to be probed between your local system and the remote machine by specifying the time, in seconds, with the m flag. The default time limit between two hops is 30 seconds for the mtr command.

Syntax:

$ mtr -m [timeInSeconds] “domainName/IP”

Example:

$ mtr -m 35 216.58.223.78

8. Specify packet size

Through the s flag in the mtr command, you can specify the size, in bytes, of the IP packet for diagnosing network quality.

Syntax:

$ mtrr -s [packetsize] “domainName/IP”

Example:

mtr -r -s 50 google.com

9. Print CSV Output

The CSV output of the mtr report delimits the columns with a “,”. With the csv flag, you can customize the mtr command to output the report in a CSV format.

Syntax:

$ mtr –csv “domainName/IP”

Example:

$ mtr --csv google.com

<img alt="Print CSV Output" data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-42.png6256b94c98825.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="312" loading="lazy" src="data:image/svg xml,” width=”733″>

10. Print XML Output

The mtr command can also support the XML format for printing traceroute reports. The XML report is a good option for automated processing of the output and can be printed by specifying the xml flag with the mtr command.

Syntax:

$ mtr –xml “domainName/IP”

Example:

$ mtr --xml google.com

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2022/04/echo/word-image-43.png6256b94cbea4e.jpg" data-ez ezimgfmt="rs rscb10 src ng ngcb10 srcset" height="568" loading="lazy" src="data:image/svg xml,” width=”769″>

11. Accessing the mtr help and man page

Finally, you can get further options for usage and customization of the mtr command by reading its help and man page through the following commands.

$ man mtr
$ mtr --help

After reading this article, you are better equipped with running network diagnostics between your machine and a remote system. You also have an alternative to the ping and traceroute commands, with many more customization options for better productivity and usefulness.