There are plenty of programs for network diagnostic. You might wonder, do we need one more?
If you want to trace the route of a query, yes! The MTR command could slightly outperform the traditional Traceroute command and give some more data, so it has a reason to exist.
What is MTR command?
MTR comes from Matt’s traceroute. First written by Matt Kimball in 1997 and later updated with Roger Wolff’s help, this is software with CLI that helps you see the route of a query.
It is based on the traditional traceroute command, but it presents each of the hops on the way, with a table-like view and data like data loss, amount of packets sent, the time of the return of each hop.
How to use Linux MTR command?
It is a command for Linux distros, but it doesn’t come pre-installed.
- Open the Terminal application.
- Now use this command for installing it.
For Ubuntu, Debian, or distros that are closely based on them, write:
sudo apt-get install mtr
Write your password and press Enter.
For CentOS, Feroda, or RedHat:
sudo yum install mtr
Again, password and Enter.
- Now you can try to ping a particular domain that you want with: mtr domainname.com. Change the Domainname.com with the one you want.
The full syntax is:
mtr [-hvrctglspni46] [–help] [–version] [–report] [–report-cycles COUNT] [–curses] [–split] [–raw] [–no-dns] [–gtk] [–address IP.ADD.RE.SS [–interval SECONDS] [–psize BYTES | -s BYTES] HOSTNAME [PACKETSIZE]
Use additional options and extend the functionality of the MTR command.
*You can easily install the MTR command on macOS with Brew (brew install mtr) or on FreeBSD (sudo pkg iWnstall package_name).
MTR available options on Linux
|Option||What is does?|
|-h–help||See all the available options.|
|-v–version||Version of the MTR command.|
|-r–report||This starts the report mode. Will run, depending on the count value (–c).|
|-w–report-wide||Wide report mode (+hostnames).|
|-c COUNT–report-cycles COUNT||Number of pings.|
|-s BYTES–psize BYTES PACKETSIZE||Packets’ size in bytes.|
|-t–curses||Curses-based terminal interface.|
|-n–no-dns||Show IP numbers instead of hostname.|
|-l–raw||Set to raw output format.|
|-a IP.ADD.RE.SS–address IP.ADD.RE.SS||Set outgoing packets’ sockets to a specified interface.|
|-i SECONDS–interval SECONDS||Interval, between the ICMP ECHO requests.|
|-u||UDP for queries.|
Examples of how to use the MTR command
Use these examples of the MTR command, and apply them with your domain names and IP addresses by simply changing that part from them.
See the route of a query
You can see the individual hops with their hostnames and statistics about the time it took and packets’ lost. You can use an IP address instead of a domain name. When you get enough data, press “Ctrl+C” to stop it.
Set a number of pings
If you want to set a particular amount of queries, you can use the “-c” option and put the number. When it finishes, it will auto-exit.
mtr -c 99 domainname.com
Print the result with the Report Mode
You can use the so-called Report Mode and put the result directly into a TXT file. It makes it practical if you want to see the result later.
mtr -r -c 99 domainname.com >TXT file name
Set time interval between the pings
You can set time in seconds, from one ICMP ECHO to another.
mtr -i 99 domainname.com
Use UDP or TCP instead of the ICMP ECHO
If you want to use one of these protocols, you can with these MTR commands:
mtr –udp domainname.com
mtr –tcp domainname.com
Set the packets’ size
You can decide what packets’ size to use for your queries. The size will be in bytes.
mtr -r -s 64 domainname.com
Set maximum time between hops
The default time is already set to 30 seconds, but you can increase it and allow a bit more waiting time for each hop. The time we set here is 60 seconds, and we use the IP address 184.108.40.206.
mtr -m 60 220.127.116.11