Linux command
mtr 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run traceroute to a host
mtr [hostname]
Use TCP instead of ICMP
mtr --tcp [hostname]
Use UDP instead of ICMP
mtr --udp [hostname]
Specify port for TCP/UDP
mtr --tcp --port [443] [hostname]
Generate a report and exit
mtr --report [hostname]
Generate report with N cycles
mtr --report --report-cycles [100] [hostname]
Show numeric IPs only without DNS resolution
mtr --no-dns [hostname]
Output as JSON
mtr --json [hostname]
说明
mtr (My TraceRoute) combines the functionality of traceroute and ping into a single network diagnostic tool. It sends packets with purposely low TTLs, continuously probing each hop along the route to a destination, and displays real-time statistics about packet loss and latency. The interactive display updates continuously, showing each router hop with loss percentage, sent/received counts, and latency statistics (best, average, worst, standard deviation). This makes it easy to identify where network problems occur. Report mode (-r) runs a fixed number of cycles (default 10) and outputs summary statistics, useful for logging and scripting. Wide report mode (-w) prevents hostname truncation. Output formats include plain text, JSON, XML, and CSV for integration with monitoring systems. TCP and UDP modes help diagnose issues when ICMP is filtered. Using TCP port 443 or 80 often reaches destinations that block ping. The tool can also detect asymmetric routing and path changes. MTR is invaluable for diagnosing intermittent network issues -- you can watch it over time to catch sporadic packet loss that a single traceroute might miss.
参数
- -r, --report
- Generate report mode output and exit.
- -c _NUM_, --report-cycles _NUM_
- Number of pings per hop (default: 10).
- -s _SIZE_, --psize _SIZE_
- Packet size in bytes.
- -T, --tcp
- Use TCP SYN packets.
- -U, --udp
- Use UDP datagrams.
- -P _PORT_, --port _PORT_
- Target port for TCP/UDP.
- -n, --no-dns
- Do not resolve hostnames.
- -b, --show-ips
- Show both hostname and IP.
- -w, --report-wide
- Wide report format (no truncation).
- -j, --json
- Output in JSON format.
- -x, --xml
- Output in XML format.
- -C, --csv
- Output in CSV format.
- -i _SECONDS_, --interval _SECONDS_
- Interval between pings.
- -m _NUM_, --max-ttl _NUM_
- Maximum TTL / hops.
- -f _NUM_, --first-ttl _NUM_
- Starting TTL.
- -4
- Use IPv4 only.
- -6
- Use IPv6 only.
- -a _ADDRESS_, --address _ADDRESS_
- Bind to source address.
- -e, --mpls
- Display MPLS information from ICMP extensions.
- -o _FIELDS_, --order _FIELDS_
- Specify fields and order for report output.
FAQ
What is the mtr command used for?
mtr (My TraceRoute) combines the functionality of traceroute and ping into a single network diagnostic tool. It sends packets with purposely low TTLs, continuously probing each hop along the route to a destination, and displays real-time statistics about packet loss and latency. The interactive display updates continuously, showing each router hop with loss percentage, sent/received counts, and latency statistics (best, average, worst, standard deviation). This makes it easy to identify where network problems occur. Report mode (-r) runs a fixed number of cycles (default 10) and outputs summary statistics, useful for logging and scripting. Wide report mode (-w) prevents hostname truncation. Output formats include plain text, JSON, XML, and CSV for integration with monitoring systems. TCP and UDP modes help diagnose issues when ICMP is filtered. Using TCP port 443 or 80 often reaches destinations that block ping. The tool can also detect asymmetric routing and path changes. MTR is invaluable for diagnosing intermittent network issues -- you can watch it over time to catch sporadic packet loss that a single traceroute might miss.
How do I run a basic mtr example?
Run `mtr [hostname]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -r, --report do in mtr?
Generate report mode output and exit.