How to use the Linux mtr (My Traceroute) command

How to use the Linux mtr (My Traceroute) command

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 20.04 and Ubuntu 22.04 LTS system, but it should work on Debian 11 as well.

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.

Installing mtr Command

The mtr command is probably not installed as a default on your system. you can install it easily with apt though.

sudo apt install mtr

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

use mtr command

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

traceroute with mtr

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

Show hostnames and IP addresses

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.

Report mode enabled in mtr command

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

Rearrange the output fields

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

Use TCP SYN packets or UDP datagrams

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

Print CSV Output

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

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

Here is a list of all mtr command-line options

Usage:
mtr [options] hostname

-F, --filename FILE read hostname(s) from a file
-4 use IPv4 only
-6 use IPv6 only
-u, --udp use UDP instead of ICMP echo
-T, --tcp use TCP instead of ICMP echo
-I, --interface NAME use named network interface
-a, --address ADDRESS bind the outgoing socket to ADDRESS
-f, --first-ttl NUMBER set what TTL to start
-m, --max-ttl NUMBER maximum number of hops
-U, --max-unknown NUMBER maximum unknown host
-P, --port PORT target port number for TCP, SCTP, or UDP
-L, --localport LOCALPORT source port number for UDP
-s, --psize PACKETSIZE set the packet size used for probing
-B, --bitpattern NUMBER set bit pattern to use in payload
-i, --interval SECONDS ICMP echo request interval
-G, --gracetime SECONDS number of seconds to wait for responses
-Q, --tos NUMBER type of service field in IP header
-e, --mpls display information from ICMP extensions
-Z, --timeout SECONDS seconds to keep probe sockets open
-M, --mark MARK mark each sent packet
-r, --report output using report mode
-w, --report-wide output wide report
-c, --report-cycles COUNT set the number of pings sent
-j, --json output json
-x, --xml output xml
-C, --csv output comma separated values
-l, --raw output raw format
-p, --split split output
-t, --curses use curses terminal interface
--displaymode MODE select initial display mode
-g, --gtk use GTK+ xwindow interface
-n, --no-dns do not resolve host names
-b, --show-ips show IP numbers and host names
-o, --order FIELDS select output fields
-y, --ipinfo NUMBER select IP information in output
-z, --aslookup display AS number
-h, --help display this help and exit
-v, --version output version information and exit

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.

How to use the Linux mtr (My Traceroute) command
read coderpad profiles:
 
http://www.lawrence.com/users/coderpad/ 
 
https://www.scribd.com/document/601722224/Coderpad

https://issuu.com/coderpad/docs/coderpad-blogspot-com-

https://linktr.ee/coderpad

https://www.pearltrees.com/coderpad

https://www.akonter.com/user/profile/coderpad
 
 
Men' fashion , Dating Tips , Relationship Advice

Post a Comment