mtr is a network diagnostic tool which combines ping and traceroute functionalities into a single command. In this article we discuss commonly used commands with mtr used for troubleshooting and gathering information about networks.
Table of contents.
mtr is a network diagnostic tool which combines ping and traceroute functionalities.
It sends packets showing ping times for each hop.
It also useful for troubleshooting network issues arising in the route taken by a packet from source to destination.
The syntax is as follows.
mtr <option> <hostname>/path
Various useful options include,
- -4 for Ipv4 ip addresses.
- -6 for Ipv6 ip addresses.
- -F, --filename FILE, so as to read hostnames from a file.
- -j, --json, to display output in json format.
- -x, --xml, to display output in xml format.
- -C, --csv, to display output in csv format.
- -c, --report-cycles COUNT, to specify the number of pings to send.
- -n, --no-dns to avoid resolving hostnames so as to increase test speed.
- -u, --udp, to use UDP instead of ICMP echo requests.
- -T, --tcp, to use TCP instead of ICMP echo requests.
- -i, --interval SECONDS, to specify ICMP echo request interval.
- -m, --max-ttl NUMBER, to define the maximum number of hops.
- -P, --port PORT, specify a target port number e.g for TCP, SCTP, or UDP protocols.
- -b, --show-ips, to show the ip and host names.
- -s, --psize PACKETSIZE, to specify a packet size e.g ICMP packet size which also includes headers in bytes.
- -r, --report, to present output in report mode.
- -w, --report-wide to display a wide report as output.
- -o, --order FIELDS to order output fields however we want to.
- -g, for a window interface.
To get started we execute the command,
mtr -c 5 -n -w google.com
Which sends 5 pings to google.com and displays the report as output.
From the output we can see the following columns,
- HOST: This represents the host number in the path from source rto destination.
- user: This is the user.
- Loss%: represents the packet loss at each host on the path.
- Snt: represents the number of sent packets.
- Last: This is the round trip time for the last traceroute packet.
- Avg: This is the average round trip time for all probes.
- Best: This represents the shortest round trip time of a packet to a host.
- Wrst: The longest round trip time of a packet to a host.
- StDev: Represents the standard deviation of latencies.
To display output in csv format we write,
mtr -c 5 --csv google.com
To display output in json format we write,
mtr -c 5 --json google.com
To display output in xml format we write,
mtr -c 5 --xml google.com
To send 5 pings we use -c option as has been used in previous commands,
mtr -c 5 google.com
We can also specify host names in a file then read from a file,
cat > hosts.txt google.com yahoo.com yandex.com
To send packets,
mtr -w -F hosts.txt
For faster tests we disable DNS resolution by using -n option,
mtr -n -w -F hosts.txt
We use the -w option so as to display wide reports.
To send packets with tcp protocol we use the --tcp option,
mtr -c 5 -w --tcp google.com
To use udp protocol we use --udp option,
mtr -c 5 -w --udp google.com
We can also rearrange the order of columns in the output,
mtr -c 5 -w -o "RS" google.com
The command only returns the received and sent columns.
More on this can be seen in a table in the manual page for mtr.
We can also specify the number of hops by using the -m option,
mtr -w -m 10 google.com
The above command specifies 10 hops.
To define the intervals between ICMP echo requests by using the -i option,
mtr -c5 -w -i 10 google.com
The above command specifies 10 seconds between echo requests.
We can also specify the packet size by using the -s option,
mtr -c5 -w -s 50 google.com
The command will send 50-byte packets.
We can also use mtr on a specified port by using the P option,
mtr -c5 -w -P 80 google.com
The command tests mtr on port 80.
mtr combines the functionalities of two very popular network diagnostic tools, ping which confirms if two hosts can communicate with each other by sending ICMP packets and traceroute which traces a path from source to destination.
- Execute man mtr for manual page or mtr --help.
- Linux networking commands