Installation and use of MTR network diagnostic tool macOS/centOS/Ubuntu

Table of contents

1.====MTR(My Traceroute)Introduction====

2.==== MTR (My Traceroute) installation ====

2.1.====macOS====

2.2.====centOS====

2.3.====Ubuntu====

3.==== MTR (My Traceroute) use ====



1.====MTR(My Traceroute)Introduction====

`mtr` (My Traceroute) is a network diagnostic tool that combines the functions of `traceroute` and `ping`.

`mtr` provides real-time reporting of network connections by sending ICMP ECHO requests to target hosts and collecting information at each network hop.

Here are some key features of `mtr`:

1. **Real-time update**: `mtr` will continue to send data packets and update the results in real time. This allows you to see changes in network performance.

2. **Statistics**: For each network hop, `mtr` will display statistics such as the number of packets sent, success rate, fastest/slowest/average round trip time.

3. **Visualization of Network Paths**: `mtr` will display all the network hops a packet takes from source host to destination host. This can help you understand network paths and identify possible problems.

When using `mtr`, you need to pay attention to the following points:

- `mtr` requires sufficient permissions to send and receive ICMP packets. On most systems, you need to run `mtr` as the root user.

- The result of `mtr` may be affected by various factors, including network congestion, router's load balancing strategy, firewall settings, etc. Therefore, you should interpret `mtr` results in conjunction with other tools and information.

- Some network devices may throttle or block ICMP packets, which may affect the result of `mtr`. For example, some devices may rate limit ICMP packets, or not respond to ICMP packets at all.

- The result of `mtr` can only reflect the current network conditions. Network performance and paths may vary over time and as network conditions change.

2.==== MTR (My Traceroute) installation ====

2.1.====macOS====

$ brew install mtr //install mtr via brew

$ echo $SHELL // check which shell the terminal uses

  • If the output is /bin/zsh, then you should add the following lines to your ~/.zshrc file:
  • If the output is /bin/bash, then you should add the following line to your ~/.bash_profile file:

$ vim ~/.zshrc //Edit the PATH environment variable of zsh shell

==== Add the following line ====

export PATH=/usr/local/sbin:$PATH

==== Add above line ====

$ source ~/.zshrc //Reload the configuration file

2.2.====centOS====

$ yum install mtr //It should be available after installing mtr

⚠️Note: If you cannot use the mtr command, use the following method

$ echo $SHELL // check which shell the terminal uses

  • If the output is /bin/zsh, then you should add the following lines to your ~/.zshrc file:
  • If the output is /bin/bash, then you should add the following line to your ~/.bash_profile file:

$ vim ~/.bash_profile //Edit the PATH environment variable of the bash shell

==== Add the following line ====

export PATH=/usr/local/sbin:$PATH

==== Add above line ====

$ source ~/.bash_profile //Reload configuration file

2.3.====Ubuntu====

$ apt install mtr //It should be available after installing mtr

⚠️Note: If you cannot use the mtr command, use the following method

$ echo $SHELL // check which shell the terminal uses

  • If the output is /bin/zsh, then you should add the following lines to your ~/.zshrc file:
  • If the output is /bin/bash, then you should add the following line to your ~/.bashrc file:

$ vim ~/.bashrc //Edit the PATH environment variable of the bash shell

==== Add the following line ====

export PATH=/usr/local/sbin:$PATH

==== Add above line ====

$ source ~/.bashrc //Reload the configuration file

3.==== MTR (My Traceroute) use ====

$ sudo mtr baidu.com //real-time mode

$ sudo mtr -r baidu.com //report mode

1. **Basic usage**: To use `mtr`, you only need to enter `mtr` on the command line, followed by the host name or IP address you want to diagnose. For example, if you want to view the path to baidu.com, you can enter the following command:

$ sudo mtr baidu.com //This command will display all the network nodes that the data packets pass from your machine to baidu.com, as well as the statistics of each node.

2. **Use report mode**: `mtr` has a report mode, which will display a statistical report after a period of time, instead of updating the results in real time. You can enable report mode with the `-r` or `--report` option. For example:

$ sudo mtr -r baidu.com //This command will send a certain number of data packets (default is 10), and then display a statistical report.

3. **Change number of packets**: In report mode, you can use `-c` or `--report-cycles` option to change the number of packets. For example, if you want to send 100 packets, you can enter the following command:

$ sudo mtr -r -c 100 baidu.com

4. **Use IPv6**: `mtr` uses IPv4 by default, but you can also use the `-6` option to enable IPv6. For example:

$ sudo mtr -6 baidu.com

Guess you like

Origin blog.csdn.net/cgxcgxcgxcgx/article/details/131908905