Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux mtr command

Linux mtr command

Linux Command Reference Linux Command Reference


mtr (My Traceroute) is a powerful network diagnostic tool that combines traceroute and ping the functions of both. It can display the transmission path of data packets in the network in real time and provide detailed statistics, making it a valuable tool for network administrators and developers to troubleshoot network issues.

Main features of mtr


Install the mtr command

Install on common Linux distributions

Example

Debian/Ubuntu systems

sudo

apt-get install

mtr

CentOS/RHEL systems

sudo

yum install

mtr

Fedora systems

sudo

dnf

install

mtr

Arch Linux systems

sudo

pacman

-S

mtr

Install on macOS

Example

Install using Homebrew

brew

install

mtr


Basic syntax of mtr

The basic syntax format of the mtr command is as follows:

mtr [选项] 目标主机

Description of common options and parameters

Option Description
-4 Force the use of IPv4
-6 Force the use of IPv6
-c COUNT Set the number of ping packets to send
-i SECONDS Set the ping interval (in seconds)
-n Do not resolve host names; display IP addresses
-r Generate report mode (non-interactive)
-s BYTES Set the ping packet size (in bytes)
-w Wide output mode, display full host names
-z Display AS (autonomous system) numbers
--report is equivalent to -r, generate a report and exit
--report-wide Wide format report

mtr usage examples

Basic usage: diagnose the network path to a target host

mtr google.com

After execution, a real-time updating interface is displayed, containing the following information:

Generate report mode (suitable for script calls)

mtr -r -c 10 google.com > mtr_report.txt

This command sends 10 ping packets to google.com and then saves the result to the mtr_report.txt file.

Set the ping packet size and interval

mtr -s 100 -i 0.5 example.com

This command sets each ping packet to 100 bytes and the interval to 0.5 seconds.

Display AS numbers at the same time

mtr -z example.com

This command displays the AS (autonomous system) number of each node in the result, which helps identify network ownership.


Interpreting mtr output

Description of the interactive interface

When running mtr, you will see output similar to the following:

My traceroute  [v0.92]

example.com (192.0.2.1)                                                                2022-01-01T12:00:00+0000

Keys:  Help   Display mode   Restart statistics   Order of fields   quit

                                                                 Packets               Pings

 Host                                                        Loss%   Snt   Last   Avg  Best  Wrst StDev

 1. 192.168.1.1                                              0.0%    10    2.1   2.2   1.9   2.5   0.2

 2. 10.0.0.1                                                 0.0%    10    5.3   5.5   5.1   6.0   0.3

 3. 203.0.113.1                                              0.0%    10   15.2  15.5  15.0  16.1   0.4

 4. example.com                                              0.0%    10   20.1  20.3  20.0  21.0   0.3

Explanation of key metrics

  1. Loss%: Packet loss rate; a higher value indicates a less stable network
  2. Snt: The number of probe packets sent
  3. Last: The latency of the most recent probe (in milliseconds)
  4. Avg: Average latency (in milliseconds)
  5. Best: Best latency (in milliseconds)
  6. Wrst: Worst latency (in milliseconds)
  7. StDev: The standard deviation of latency, reflecting network stability

Advanced usage and tips

1. Trace IPv4 and IPv6 paths at the same time

Example

mtr

-4

example.com  

IPv4 path

mtr

-6

example.com  

IPv6 path

2. Use TCP SYN instead of ICMP (to bypass certain firewalls)

mtr --tcp example.com

3. Specify the source port (for specific route tests)

mtr --port 8080 example.com

4. Save results to CSV format

mtr --csv example.com > result.csv

5. Compare network conditions at two points in time

Example

mtr

-c

60

-i

1

-w

example.com

result1.txt

After some time

mtr

-c

60

-i

1

-w

example.com

result2.txt

diff

result1.txt result2.txt


Troubleshooting common problems

1. High packet loss rate issues

If a high packet loss rate occurs at a certain node:

2. Sudden latency spikes

If latency suddenly increases at a certain node:

3. Asterisk (*) display

If you see an asterisk (*) instead of an IP address:


Comparison of mtr with other tools

Tool Real-time updates Bidirectional diagnosis Packet loss statistics Latency statistics Interactive interface
ping ❌ ❌ ✔️ ✔️ ❌
traceroute ❌ ❌ ❌ ✔️ ❌
mtr ✔️ ✔️ ✔️ ✔️ ✔️

Practical Exercise

  1. Use mtr to check the network path to your frequently visited websites
  2. Compare the network quality differences between Wi-Fi and wired connections
  3. Try testing network performance with ping packets of different sizes
  4. Set up a scheduled task to periodically generate network quality reports

Example

Example: Generate a network status report every day

(

crontab

-l

2

/

dev

/

null;

echo

"0 2 * * * /usr/sbin/mtr -r -c 100 google.com > ~/network_report_$(date +%Y%m%d).txt"

)

|

crontab -


Summary

mtr is a powerful network diagnostic tool that combines the strengths of traceroute and ping, providing real-time, comprehensive network path analysis. Through this article, you should be able to:

  1. Understand the basic principles and working mechanism of mtr
  2. Use mtr skillfully to diagnose network problems
  3. Interpret the various metrics in mtr output
  4. Apply mtr to solve real-world network problems

Mastering the mtr command will greatly improve your efficiency in troubleshooting network issues and is a skill that every system administrator and developer should possess.


Linux Command Reference Linux Command Reference