How to Use the Linux mtr Command
How to Use the Linux mtr Command
The mtr (My Traceroute) command is a powerful network diagnostic tool that combines the functionality of both ping and traceroute. It provides real-time insights into the route data packets take to reach a destination, as well as the packet loss and latency of each hop. This guide will show you how to install and use the mtr command on Linux.
Step 1: Install mtr
Before using mtr, you need to install it. Follow the instructions based on your Linux distribution:
For Ubuntu/Debian:
sudo apt update
sudo apt install mtr
For Fedora:
sudo dnf install mtr
For Arch Linux:
sudo pacman -S mtr
Step 2: Using the mtr Command
To start using mtr, simply run the command followed by a hostname or an IP address. For example, to trace the route to Google:
mtr google.com
This will provide a real-time display of the route your packets take to reach Google’s servers, updating dynamically as data flows through each hop.
Step 3: Understanding the Output
The mtr output contains several columns of important information:
Host: The name or IP address of each hop.
Loss%: Percentage of packet loss at each hop.
Sent: Number of packets sent.
Last: The latency (in milliseconds) of the most recent packet.
Avg: The average round-trip time.
Best: The lowest round-trip time.
Wrst: The highest round-trip time.
StDev: Standard deviation, showing the variability in latency.
Step 4: Running mtr as Root
For more detailed results and to avoid permission issues, you should run mtr as root. Use sudo:
sudo mtr google.com
Step 5: Running mtr in Report Mode
To generate a static report instead of real-time updates, use the -r option. This is useful for logging or sharing results with others:
mtr -r google.com
You can also specify the number of packets to send using the -c option. For example, to send 10 packets:
mtr -r -c 10 google.com
Step 6: Customize Output with Options
The mtr command provides several useful options to customize its output. Some key options include:
–n: Display numerical IP addresses instead of resolving hostnames:
mtr -n google.com
-4 or -6: Force mtr to use IPv4 or IPv6, respectively:
mtr -4 google.com
mtr -6 google.com
-b: Show both hostnames and IP addresses:
mtr -b google.com
Step 7: Analyze Network Issues
By using mtr, you can quickly identify packet loss, high latency, or other issues along the route between your machine and a remote server. Persistent high packet loss at a specific hop may indicate network congestion or problems with a router.
Conclusion
The mtr command is an invaluable tool for diagnosing network connectivity issues in real-time. It combines the best aspects of ping and traceroute, providing an easy-to-understand overview of network performance.
For more advanced usage and detailed options, you can refer to the official MTR documentation.