Linux mtr
command provides both functionality of traceroute
and ping
commands. mtr
can provide reports and xml, json, csv output. There is also Gtk interface provided for mtr
.
Interactive Traceroute
One of the simple use case for mtr
is providing the remote hostname or IP address we want to traceroute. This will open a new interactive window which shows each intermediate hop. This will also send continuous ICMP packets to get new time and related metrics and show in the screen.
$ mtr google.com
We can exit from this screen with CTRL+C
Show Gtk Interface
mtr
command can be used with GUI interface. We will provide –g
in order to start with Gtk interface.
$ mtr -g google.com
CSV Output
We can create CSV type output. CSV type output will delimit the columns with ,
. We will provide --csv
option with the remote hostname.
$ mtr --csv google.com

Xml Output
Another supported output is xml
. We can generate xml format output for the given remote hostname. We will use --xml
option for this. Xml format is better suited for automated processing.
$ mtr --xml google.com

Json Output
We can also generate Json output. Json format is mainly used by Javascript applications. We can use --json
option to generate JSON output.
$ mtr --json google.com

Set Ping Count
mtr
command will generate ping packets continuously. We can specify the ping count with –c
and the packet count. In this example we will set ping count to 5 .
$ mtr -c 5 google.com
Read Hostnames From File
We can provide multiple hostnames to ping. In order to provide multiple remote hosts we should put them in to a file line by line. Then we will read this file with -F
option with the file name. In this example we will read remote hosts from file named ping.txt
.
$ mtr -F ping.txt
Do Not Resolve DNS
Another standard feature of mtr
is disabling DNS resolving. This will made operations faster because extra DNS resolving will create more traffic and wait time. We can disable DNS resolving with -n
option.
$ mtr -n google.com
Show AS Number
Autonomous systems are cells in internet network each of them connects each other in a mesh way. During ping and traceroute operations send packets are transmitted trough these Autonomous systems. We can all intermediate hosts autonomous numbers with --aslookup
option.
$ mtr --aslookup google.com
