mtr Command in Linux



The mtr command stands for My Traceroute. It is a useful tool in Linux that combines the features of both the ping and traceroute commands. It gives real-time information about network performance and helps identify connection problems by showing the path packets take from your computer to a destination.

Table of Contents

Here is a comprehensive guide to the options available with the mtr command −

What is mtr Command in Linux?

mtr is a network diagnostic tool that combines the functionality of ping and traceroute commands to provide real-time network analysis. The ping checks whether a destination is reachable and measures round-trip time, and the traceroute command maps the route packets take to reach the destination. On the other hand, the mtr command continuously monitors and reports the network route and packet loss statistics in real-time.

The mtr command is often used to pinpoint network bottlenecks or problems in the data transfer process, such as packet loss or high latency.

Why Use mtr Command?

mtr is more helpful than traditional tools like ping or traceroute because it combines both features and provides real-time monitoring. This allows you to spot network problems more quickly and efficiently.

Here are some reasons that shows why you should use mtr command in Linux −

  • mtr continuously sends packets to the target and updates the results, which gives you live information about network performance.
  • mtr can detect packet loss and delays at each step, which helps you find where the issue is.
  • The results are shown in an interactive and dynamic format, making it easier to read and understand the data.

How to Install mtr Command in Linux?

The mtr tool can be easily installed on any Linux distribution using your system's package manager. For example, you can install it on Ubuntu/Debian-based systems using apt, as shown below −

sudo apt install mtr
mtr Command in Linux1

Similarly, you can use yum package manager to install mtr on CentOS/RHEL-based systems −

sudo yum install mtr

Fedora users can use dnf to install this command on their systems −

sudo dnf install mtr

Once mtr is installed on your system, you can verify its installation with the following command −

mtr --version
mtr Command in Linux2

Syntax of mtr Command

To use mtr command on a Linux system, you must follow the below syntax −

mtr [options] <destination>

Here <destination> is the IP address or domain name of the target server you want to diagnose. Some commonly used options include −

mtr Command Options

Option Description
-r It displays a one-time snapshot of the results instead of continuously updating.
-c It specifies the number of packets to send to each hop (default is 10).
-i It sets the interval (in seconds) between sending each packet (default is 1 second).
-n It prevents DNS resolution and shows IP addresses only.
-w It uses a wide output format for better readability.
-p It specifies the port to use for the traceroute (default is 80 for HTTP).

Examples of mtr Command in Linux

Let's go through the following examples to get a better understanding of the Linux mtr command −

mtr google.com

It shows the network path and performance data between your system and google.com −

mtr Command in Linux3

When we run the mtr command, the output displays a list of hops (routers or intermediate devices) that your packets pass through on their way to the destination.

For each hop, mtr returns the following information −

  • Hostname − The IP address or domain name of the device.
  • Loss% − The percentage of lost packets at that step.
  • Sent − The number of packets sent to that step.
  • Recv − The number of packets received from that step.
  • Best − The quickest round-trip time (RTT) for that step.
  • Avg − The average round-trip time for that step.
  • Worst − The slowest round-trip time for that step.
  • Stdev − The variation in round-trip time for that step.

Basic Usage of mtr Command

Let's use the mtr command with different options to understand its working −

mtr -r -c 20 -n google.com

This command will run in report mode, sending 20 packets to google.com without resolving DNS names −

mtr Command in Linux4

Advanced Usage of mtr Command

To get more detailed information about the hops, you can run mtr with root privileges. This allows it to use ICMP (ping) and send data at the lowest network level.

sudo mtr google.com

Using mtr in Combination with Other Commands

You can use mtr in combination with other commands like grep or tee to filter or save the output. For example, the following command saves the output to a file for further analysis −

sudo mtr google.com -r -c 10 | tee mtrOutput.txt
mtr Command in Linux5

You can access the file anytime to view and analyze the output −

cat mtrOutput.txt
mtr Command in Linux6

Troubleshooting Network Issues with mtr Command

mtr is extremely helpful for diagnosing network issues such as high latency, packet loss, or unreliable routing. Here's how to use mtr for troubleshooting −

  • If you see high round-trip times (RTT) in the Avg or Worst columns for any hop, it could mean there's a delay in the network. This usually happens because of network congestion or setup problems.
  • If you notice a high percentage of packet loss (e.g., Loss over 10%) at any hop, it could be due to a broken router or a busy network. You can find the problem area and work with your network team or service provider to fix it.
  • If packet loss or high latency happens at a specific hop, it might be a routing issue or a bottleneck in the network. By looking at the path and delay of different hops, you can find where the problem is.

That's all about the mtr command in Linux.

Conclusion

The mtr command is a valuable tool for network diagnostics in Linux. It provides real-time insights into network performance and helps pinpoint issues like packet loss or high latency by combining the functions of both ping and traceroute.

mtr offers a powerful and efficient way to get detailed information for troubleshooting network problems, analyzing routing paths, or monitoring network health.

With its easy installation, user-friendly output, and ability to integrate with other commands, mtr is an essential tool for anyone managing or troubleshooting networks in Linux environments.

Advertisements