Network diagnostic tool-mtr command
Recently, during an interview, I was asked about the mtr command, and I was confused. According to the interviewer, this command is commonly used in the company, so I would like to learn it too!
Network Diagnostics Background
Network diagnostic tools include ping
, traceroute
and mtr,
they use Internet Control Message Protocol (ICMP) packets to test connections and transmissions between two points on the Internet.
When a user pings a host on the Internet, a series of ICMP packets are sent to the host, and the host responds by sending packets. The user's client can then calculate the round trip time between two points on the Internet. Instead, tools like traceroute and MTR send ICMP packets with their TTL incremented, allowing you to view the series of hops the packet makes between the source and destination. TTL, or time to live, controls how many hops a packet will make before it "dies" and returns to the host . By sending a series of packets and returning them one, two, and three hops later, MTR can analyze the paths of traffic between different hosts on the Internet .
Rather than just providing a simple overview of the Internet's routes, MTR collects additional information about the status, connectivity, and responsiveness of intermediate hosts . Thanks to this additional information, MTR can provide a complete description of the connection between two hosts on the Internet.
Introduction to mtr command
The next more useful network connectivity judgment tool under Linux can be combined with ping nslookup tracert to judge the relevant characteristics of the network . This command is mtr. The full name of mtr is my traceroute, which is a network diagnostic tool that combines ping and traceroute into one program.
Install
[root@felix_server ~]# yum install -y mtr
mtr report parameter analysis
[root@felix_server ~]# mtr -r www.baidu.com
parameter name | meaning |
---|---|
HOST | host name, ip address |
Loss% | Packet loss percentage per hop |
Snt | Number of packets sent |
Last | The delay of the last packet sent |
Avg | Average latency of all packets |
Best | Best (shortest) round trip time for packets to this host |
Wrst | Best worst (longest) round trip time for packets to this host |
StDev | Latency standard deviation per host. The larger the standard deviation, the greater the difference between latency measurements |
Command option meaning
Options | meaning |
---|---|
-r | Print the mtr diagnostic report. If you do not use the -r or --report parameter, mtr will continue to run dynamically. |
-s | Specify the size of ping packets |
-c | Specify the delivery quantity |
-n | No hostname or domain name resolution |
-i | Set the requirement between ICMP returns. The default is 1 second. |
Case
Print mtr diagnostic report
[root@felix_server ~]# mtr -r www.baidu.com
Start: Sun Jun 11 12:56:54 2023
HOST: felix_server Loss% Snt Last Avg Best Wrst StDev
1.|-- gateway 0.0% 10 2.1 3.7 1.7 18.6 5.2
2.|-- 192.168.0.1 0.0% 10 2.4 2.4 1.5 3.5 0.3
3.|-- 175.0.148.1 0.0% 10 33.2 18.0 3.9 98.0 29.4
4.|-- 61.187.32.125 80.0% 10 7.0 6.2 5.4 7.0 1.0
5.|-- 61.137.11.177 80.0% 10 12.2 11.6 11.0 12.2 0.0
6.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
7.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
8.|-- 121.14.14.138 20.0% 10 20.0 25.3 19.4 48.4 10.0
9.|-- 14.29.117.142 80.0% 10 30.7 33.2 30.7 35.7 3.5
10.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
11.|-- 14.119.104.254 0.0% 10 18.9 19.4 18.3 20.4 0.3
Without domain name resolution, set the number of packets sent and the size of the packets sent.
[root@felix_server ~]# mtr -r -n -c 20 -s 100 www.baidu.com
Start: Sun Jun 11 13:14:29 2023
HOST: felix_server Loss% Snt Last Avg Best Wrst StDev
1.|-- 192.168.31.1 0.0% 20 1.7 2.0 1.6 2.4 0.0
2.|-- 192.168.0.1 0.0% 20 1.9 2.5 1.5 7.7 1.2
3.|-- 175.0.148.1 0.0% 20 5.4 8.5 4.2 16.0 3.9
4.|-- 61.187.32.125 75.0% 20 3.8 4.8 3.8 5.6 0.7
5.|-- 61.137.11.173 65.0% 20 20.4 12.8 8.3 20.4 5.4
6.|-- ??? 100.0 20 0.0 0.0 0.0 0.0 0.0
7.|-- 113.96.4.102 95.0% 20 27.8 27.8 27.8 27.8 0.0
8.|-- 219.135.96.94 0.0% 20 20.6 23.3 19.2 46.8 7.1
9.|-- 121.14.67.170 70.0% 20 25.6 37.0 24.4 61.9 13.7
10.|-- ??? 100.0 20 0.0 0.0 0.0 0.0 0.0
11.|-- 14.119.104.189 0.0% 20 25.8 24.5 22.4 26.8 0.8