In this guide, we want to teach you How To Install and Use the mtr (My Traceroute) command on Linux.
MTR (My Traceroute) or Matt’s TraceRoute is one of the most popular Traceroute tools available online. The tool has become one of the go-to tools for replacing Ping and Traceroute. MTR network monitor is an invaluable diagnostic tool that can be used to poll remote servers and measure the change of latency over time.
MTR is a useful tool for a number of reasons. First, it combines Ping and Traceroute together to be able to measure the availability of devices in the network as well as monitor the route. However, it also has a significant advantage over Traceroute because the output is updated continuously. With Traceroute, you have to update scans manually to measure how a network’s performance changes over time.
In contrast, you can run MTR and your information will be connected until you say stop. Being able to monitor the change in network performance over time helps when it comes to troubleshooting.
Steps To Install and Use mtr Command on Linux
To complete this guide, you can log in to your Linux server as a root or non-root user with sudo privileges.
Now follow the steps below to see how it works.
Install mtr on Linux
You can easily install mtr on your server.
On Debian / Ubuntu use the command below to install mtr:
sudo apt install mtr
On Centos / RHEL use the following command:
yum install mtr dnf install mtr
When your installation is completed, proceed to the next step.
How To Use mtr on Linux
When using the mtr network scanner, you need to generate an mtr report in order to view your traffic data. mtr reports are directional so it is necessary to generate reports in both directions to get a complete picture of your network’s performance.
In this section we’re going to look at:
- Display Hostnames
- Display Numeric IP addresses
- Specify a limit for the number of pings
- Enable Report Mode
- Clear output in Report
- Specify Time Interval between ICMP ECHO requests
- Use TCP SYN packets or UDP datagrams
- Specify packet size
- Print CSV Output
- Print XML Output
- Accessing the mtr help and man page
The basic syntax for the mtr command is as follows:
mtr <option> <hostname>/path
Display Hostnames and Numeric IP address
The mtr command displays the hostnames in the traceroute report. To do this, you can use the following command:
Example Output My traceroute [v0.94] Keys: Help Display mode Restart statistics Order of fields quit Packets Pings Host Loss% Snt Last Avg Best Wrst StDev 1. 2a04:9dc0:c1:144::1 0.0% 21 6.3 18.9 1.3 110.0 32.2 2. eth-25-0.core-agg2.buc.ro.m247.c 0.0% 21 0.7 0.7 0.5 1.5 0.2 3. 2a04:9dc0:b1:145::1 0.0% 21 1.0 1.5 0.6 6.0 1.5 4. 2a01:300:c:0:185:206:226:99 0.0% 21 0.8 0.8 0.7 1.2 0.1 ....
Also, you can use the -g option, to see the numeric IP addresses instead of hostnames:
mtr -g google.com
To see both hostnames and IP addresses, you can use the -b option in the mtr command:
mtr -b google.com
Set a limit for the Number of Pings
You can easily configure the mtr command to set a limit for your pings. The syntax used to do this is as follows:
mtr -c [n] “domainname/IP”
mtr -c 10 google.com
Enable mtr Report Mode
Instead of looking at the screen all the time, we can let mtr do the job for a while and read the result later with the -r option. For example:
mtr -r google.com
Output Start: 2022-12-08T03:03:59-0500 HOST: mydeb Loss% Snt Last Avg Best Wrst StDev 1.|-- 2a04:9dc0:c1:144::1 0.0% 10 3.8 6.4 1.0 12.3 4.2 2.|-- eth-25-0.core-agg2.buc.ro 0.0% 10 0.5 0.6 0.5 0.8 0.1 3.|-- 2a04:9dc0:b1:145::1 0.0% 10 0.8 0.8 0.6 1.4 0.2 4.|-- 2a01:300:c:0:185:206:226: 0.0% 10 0.7 0.9 0.6 3.1 0.8 5.|-- m247.bucarest1.buc.seabon 0.0% 10 72.3 48.1 43.7 72.3 8.7 6.|-- fra31-loop0-v6.fra.seabon 0.0% 10 25.4 29.5 25.4 54.8 9.4 7.|-- ipv6.de-cix.fra.de.as1516 0.0% 10 25.8 26.1 25.4 29.4 1.2 8.|-- 2001:4860:0:11df::10 0.0% 10 25.7 26.3 25.5 31.2 1.7 9.|-- 2001:4860::c:4000:f874 20.0% 10 25.8 27.8 25.8 37.4 3.9 10.|-- 2001:4860::c:4001:e5e9 0.0% 10 35.1 33.5 32.3 38.6 2.0 11.|-- 2001:4860::9:4002:9cd8 0.0% 10 64.2 54.7 53.4 64.2 3.4 12.|-- 2001:4860:0:16c::1 0.0% 10 53.5 53.6 53.3 54.6 0.4 13.|-- 2001:4860:0:1::3dd7 0.0% 10 53.6 53.6 53.4 54.3 0.3 14.|-- sof04s06-in-x0e.1e100.net 0.0% 10 53.4 53.7 53.2 55.8 0.8
You can specify a ping count for which you want to limit the report through the -c option, and also specify the report filename in which the report will be saved:
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.
Also, you can clear output in the mtr report mode. To do this, you can add the -w option.
mtr -rw -c 10 google.com >mtr-report-google
Specify Time Interval
At this point, you can slow down the packets you sent with the -i option:
mtr -i [time-in-seconds] “domainName/IP”
mtr -i 10 google.com
The omitted output is the same as if we don’t use the -i option. The only difference is the slower increase of the value in the Snt column. The default value of -i is 1, so this command is 10 times slower, meaning the interval between sent packets is 10 times longer.
The option is useful when we don’t want to swamp the network with our packets.
TCP and UDP
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.
$ mtr –tcp “domainName/IP” $ mtr –udp “domainName/IP”
$ mtr --tcp google.com $ mtr --udp google.com
Specify packet size
Through the -s option in the mtr command, you can specify the size, in bytes, of the IP packet for diagnosing network quality.
mtr –r -s [packetsize] “domainName/IP”
mtr -r -s 50 google.com
Print CSV Output
The CSV output of the mtr report delimits the columns with a “,”. With the csv option, you can customize the mtr command to output the report in a CSV format.
mtr –csv “domainName/IP”
mtr --csv google.com
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 option with the mtr command.
mtr –xml “domainName/IP”
mtr --xml google.com
mtr help and man page
Finally, you can get more options for usage and customization of the mtr command on Linux by reading its help and man page through the following commands:
Output 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 See the 'man 8 mtr' for details.
At this point, you have learned to Install and Use the mtr command on Linux.
Hope you enjoy it.
You may be like these articles:
How To Use Ping Command in Linux
How To Install and Use tmux on Linux