‘mtr’ Command | Linux Network Administration Guide

Graphic of Linux terminal using mtr command focusing on network diagnostics and route tracing

Are you finding it challenging to diagnose network issues in Linux? You’re not alone. Many system administrators and developers find themselves in a maze when it comes to network diagnostics, but there’s a tool that can simplify this process.

The ‘mtr’ command in Linux combines the functionality of the traceroute and ping commands into a single tool. This powerful command provides a one-stop solution for diagnosing and resolving network issues.

In this guide, we’ll walk you through the process of using the mtr command in Linux, from the basics to more advanced techniques. We’ll cover everything from executing simple mtr commands, understanding the output, to troubleshooting common network issues using mtr.

So, let’s dive in and start mastering the mtr command in Linux!

TL;DR: How Do I Use the MTR Command in Linux?

To use the ‘mtr’ command, you simply type mtr followed by the domain name or IP address you want to trace, mtr example.com. It combines the functionality of the traceroute and ping commands to provide comprehensive network diagnostics.

Here’s a simple example:

mtr ioflood.com

This command will start sending packets to ioflood.com and display the route that the packets take, along with other useful information such as packet loss and latency.

This is just a basic use of the mtr command in Linux, but there’s much more to learn about this versatile tool. Continue reading for more detailed information and advanced usage scenarios.

Basic Use: MTR Command in Linux

The mtr command is a network diagnostic tool that combines the functionality of two popular commands: traceroute and ping. It allows you to trace the route that your data packets take from your system to the destination server, while also providing statistics about each hop along the way.

To start with, you can use the mtr command followed by a domain name or an IP address. This will start sending packets to the destination and display the route that these packets take.

Let’s take a look at a basic example:

mtr google.com

# Output:
# MY_HOST - 0.0% - 1.1/1.1/1.1/0.0 ms
# 192.168.1.1 - 0.0% - 1.2/1.2/1.2/0.0 ms
# 10.2.1.1 - 0.0% - 11.7/11.7/11.7/0.0 ms
# 172.217.14.238 - 0.0% - 12.2/12.2/12.2/0.0 ms

In the output, each line represents a ‘hop’ along the route. The percentages represent packet loss at each hop, and the times represent the average, best, and worst round-trip times.

One of the key advantages of the mtr command is that it provides real-time, continuous network diagnostics, which can be very helpful when you’re trying to identify intermittent network issues. However, it’s worth noting that because mtr provides real-time results, it can consume a significant amount of bandwidth if left running for a long time.

Also, keep in mind that the mtr command may require root privileges depending on your system’s configuration, so if you encounter any permission issues, try running it with sudo:

sudo mtr google.com

# Output:
# MY_HOST - 0.0% - 1.1/1.1/1.1/0.0 ms
# 192.168.1.1 - 0.0% - 1.2/1.2/1.2/0.0 ms
# 10.2.1.1 - 0.0% - 11.7/11.7/11.7/0.0 ms
# 172.217.14.238 - 0.0% - 12.2/12.2/12.2/0.0 ms

This command will provide the same output as the previous one, but it will be able to run even if the initial mtr command was blocked due to insufficient permissions.

Advanced Use of MTR Command Options

The mtr command in Linux is an incredibly versatile tool, and its power goes beyond the basic usage. By using different options and flags, you can customize the mtr command to suit your specific needs and get more detailed information about your network connections.

Before we dive into the advanced usage of mtr, let’s familiarize ourselves with some of the command-line arguments or flags that can modify the behavior of the mtr command. Here’s a table with some of the most commonly used mtr arguments.

ArgumentDescriptionExample
-rReport mode.mtr -r example.com
-cSet the number of pings sent.mtr -c 10 example.com
-sSet the packet size.mtr -s 100 example.com
-pDisplay output in a format suitable for a printer.mtr -p example.com
-nDisplay numeric IPs.mtr -n example.com
-4Use IPv4 only.mtr -4 example.com
-6Use IPv6 only.mtr -6 example.com
-gEnable GNU plot output.mtr -g example.com
-lEnable latency output.mtr -l example.com
-aSet the local address.mtr -a 192.0.2.0 example.com
-fSet the first TTL.mtr -f 5 example.com
-mSet the maximum TTL.mtr -m 30 example.com
-zDisplay the timezone.mtr -z example.com

Now that we have a basic understanding of mtr command line arguments, let’s dive deeper into the advanced use of mtr.

Using Report Mode

The -r option puts mtr into report mode. In this mode, mtr will run for the number of cycles specified by the -c option (or 10 if not specified), then print statistics and exit. This mode is useful for generating reports or for automated metrics collection.

Here’s an example:

mtr -r -c 5 example.com

# Output:
# Start: 2022-03-09T14:52:10+0000
# HOST: localhost Loss% Snt Last Avg Best Wrst StDev
# 1.|-- 192.168.1.1 0.0% 5 1.2 1.2 1.1 1.3 0.1
# 2.|-- 10.2.1.1 0.0% 5 11.7 11.7 11.6 11.8 0.1
# 3.|-- 172.217.14.238 0.0% 5 12.2 12.2 12.1 12.3 0.1

In the output, each line represents a ‘hop’ along the route. The ‘Loss%’ column shows packet loss at each hop, and the ‘Last’, ‘Avg’, ‘Best’, ‘Wrst’, and ‘StDev’ columns show the last, average, best, worst, and standard deviation of round-trip times in milliseconds.

Displaying Numeric IPs

By default, mtr attempts to resolve the IP addresses to hostnames. However, you can use the -n option to display numeric IPs instead. This can be useful when you’re dealing with a slow DNS server, or when the hostnames are not meaningful to you.

Here’s an example:

mtr -n example.com

# Output:
# MY_HOST - 0.0% - 1.1/1.1/1.1/0.0 ms
# 192.168.1.1 - 0.0% - 1.2/1.2/1.2/0.0 ms
# 10.2.1.1 - 0.0% - 11.7/11.7/11.7/0.0 ms
# 172.217.14.238 - 0.0% - 12.2/12.2/12.2/0.0 ms

In this output, the IP addresses are displayed instead of hostnames. This can be much faster and more reliable, especially in environments with slow or unreliable DNS servers.

Exploring Alternatives to MTR Command

While the mtr command is an excellent tool for network diagnostics, it’s not the only method available. There are other commands, such as traceroute and ping, which can also be used separately for diagnosing network connections. Let’s explore these methods and understand their usage, effectiveness, and how they compare to mtr.

Traceroute: Mapping the Journey of Packets

The traceroute command is a network diagnostic tool that’s used to display the path that packets take from the source to the destination. It also provides transit delay of packets across the network.

Here’s an example of how you can use the traceroute command:

traceroute example.com

# Output:
# traceroute to example.com (93.184.216.34), 30 hops max, 60 byte packets
# 1  router (192.168.1.1)  1.235 ms  1.211 ms  1.185 ms
# 2  10.2.1.1 (10.2.1.1)  11.632 ms  11.613 ms  11.589 ms
# 3  93.184.216.34 (93.184.216.34)  12.345 ms  12.321 ms  12.297 ms

In the output, each line represents a ‘hop’ along the route. The times represent the transit delay of packets across the network.

Traceroute can be a useful tool when you’re trying to identify where packet loss or high latency is occurring in the network. However, unlike mtr, traceroute does not provide continuous output, which makes it less suitable for diagnosing intermittent network issues.

Ping: Checking Network Connectivity

The ping command is another network diagnostic tool that’s used to check the network connectivity between the source and the destination. It sends ICMP Echo Request packets to the destination and waits for an Echo Reply.

Here’s an example of how you can use the ping command:

ping -c 4 example.com

# Output:
# PING example.com (93.184.216.34) 56(84) bytes of data.
# 64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=11.632 ms
# 64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=11.726 ms
# 64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=11.912 ms
# 64 bytes from 93.184.216.34: icmp_seq=4 ttl=56 time=11.882 ms

# --- example.com ping statistics ---
# 4 packets transmitted, 4 received, 0% packet loss, time 3003ms
# rtt min/avg/max/mdev = 11.632/11.788/11.912/0.123 ms

In the output, each line represents a packet sent to the destination. The ‘time’ represents the round-trip time for each packet. At the end, a summary of the ping command is displayed, showing the number of packets transmitted and received, packet loss, and round-trip time.

The ping command can be an effective tool for checking network connectivity and latency. However, unlike mtr, it does not provide any information about the route that the packets take to reach the destination.

Making the Right Choice

While mtr, traceroute, and ping all serve similar purposes, they each have their own strengths and weaknesses. The mtr command provides a comprehensive view of the network path and performance, making it an excellent choice for most network diagnostics. However, for simpler tasks such as checking network connectivity or mapping the route of packets, the ping and traceroute commands may be sufficient.

Ultimately, the tool you choose will depend on your specific needs and the nature of the network issue you’re trying to diagnose.

Troubleshooting Issues with MTR Commands

While the mtr command is a powerful tool for network diagnostics, you might encounter some issues or errors during its usage. Let’s discuss some of these common issues and provide solutions and workarounds to ensure a smooth network diagnostic process.

‘Network is Unreachable’

One of the common issues you might encounter when using the mtr command is the ‘Network is unreachable’ error. This error typically occurs when there’s no route to the destination address. It might be due to network issues, incorrect network configuration, or the destination might be down.

To resolve this issue, you can first try pinging the destination to check if it’s up and running. If the destination is reachable, check your network configuration, or try resetting your network.

ping -c 4 unreachable.com

# Output:
# connect: Network is unreachable

In this example, the ‘Network is unreachable’ error is displayed when trying to ping a destination that is not reachable.

Problems with Packet Loss

Another common issue with the mtr command is high packet loss. Packet loss can occur due to various reasons, including network congestion, faulty hardware, or network configuration issues.

To troubleshoot packet loss, you can use the mtr command to identify where the packet loss is occurring. If the packet loss is happening at a specific hop, it might be an issue with that particular network node. If the packet loss is spread across all hops, it might be a problem with your network.

mtr -c 4 packetloss.com

# Output:
# MY_HOST - 25.0% - 1.1/1.1/1.1/0.0 ms
# 192.168.1.1 - 25.0% - 1.2/1.2/1.2/0.0 ms
# 10.2.1.1 - 25.0% - 11.7/11.7/11.7/0.0 ms
# 93.184.216.34 - 25.0% - 12.2/12.2/12.2/0.0 ms

In this example, there’s a 25% packet loss at each hop, indicating a potential issue with your network.

Permission Denied Error

In some cases, you might encounter a ‘Permission denied’ error when running the mtr command. This is usually because the mtr command requires root privileges to run.

You can resolve this issue by running the mtr command with sudo. However, be careful when using sudo, as it gives the command full system permissions.

sudo mtr permissiondenied.com

# Output:
# MY_HOST - 0.0% - 1.1/1.1/1.1/0.0 ms
# 192.168.1.1 - 0.0% - 1.2/1.2/1.2/0.0 ms
# 10.2.1.1 - 0.0% - 11.7/11.7/11.7/0.0 ms
# 93.184.216.34 - 0.0% - 12.2/12.2/12.2/0.0 ms

In this example, running the mtr command with sudo resolves the ‘Permission denied’ error.

By understanding these common issues and their solutions, you can make full use of the mtr command for network diagnostics and troubleshooting. Remember, the key to effective troubleshooting is to understand the problem, isolate the issue, and apply the appropriate solution.

Understanding Network Diagnostics and MTR Fundamentals

Before we delve further into the mtr command, it’s important to understand the basic principles of network diagnostics and some of the underlying concepts. This includes understanding what the ICMP protocol is, how IP routing works, and how these play into using the mtr command.

Demystifying ICMP Protocol

The Internet Control Message Protocol (ICMP) is a supporting protocol in the Internet protocol suite. It is used by network devices, like routers, to send error messages and operational information. When you use mtr, ICMP Echo Request and Echo Reply messages are used to determine the path and measure transit delays of packets across an IP network.

ping -c 4 example.com

# Output:
# PING example.com (93.184.216.34) 56(84) bytes of data.
# 64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=11.632 ms
# 64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=11.726 ms
# 64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=11.912 ms
# 64 bytes from 93.184.216.34: icmp_seq=4 ttl=56 time=11.882 ms

# --- example.com ping statistics ---
# 4 packets transmitted, 4 received, 0% packet loss, time 3003ms
# rtt min/avg/max/mdev = 11.632/11.788/11.912/0.123 ms

In this example, the ‘ping’ command sends ICMP Echo Request packets to ‘example.com’ and waits for an Echo Reply. The round-trip time is displayed in the output, which is the time taken for the ICMP Echo Request to reach the destination and for the Echo Reply to return.

IP Routing: The Journey of Data Packets

IP routing is the process of sending data from its source to its destination over the internet. When you send data over the internet, it doesn’t travel directly to its destination. Instead, it passes through multiple routers along the way — this is the essence of IP routing.

When you use the mtr command, it displays the route (path) and measures transit delays of packets across the IP network. The ‘hops’ you see in the output of the mtr command represent the routers that the data packets pass through on their way to the destination.

mtr -c 4 example.com

# Output:
# MY_HOST - 0.0% - 1.1/1.1/1.1/0.0 ms
# 192.168.1.1 - 0.0% - 1.2/1.2/1.2/0.0 ms
# 10.2.1.1 - 0.0% - 11.7/11.7/11.7/0.0 ms
# 93.184.216.34 - 0.0% - 12.2/12.2/12.2/0.0 ms

In this example, each line in the output represents a ‘hop’ or router that the data packets pass through on their way to ‘example.com’. The times represent the transit delay of packets across the network.

By understanding these fundamental concepts, you’ll have a better grasp of what the mtr command does and how to interpret its output. This knowledge forms the foundation for effective network diagnostics using the mtr command.

The Bigger Picture: Network Diagnostics and Beyond

The mtr command, while a simple tool, plays a significant role in the bigger picture of network diagnostics. Its utility extends beyond just identifying network issues, but also into essential fields like system administration and network engineering.

The Role of MTR in System Administration

In system administration, ensuring the smooth operation of network connections is a critical task. The mtr command serves as an invaluable tool in a system administrator’s toolkit. It helps in monitoring network performance, identifying bottlenecks, and troubleshooting network issues in real-time. Understanding how to effectively use the mtr command can significantly improve a system administrator’s efficiency in managing network-related tasks.

Network Engineering and MTR

Similarly, in network engineering, the mtr command is a powerful tool for diagnosing network problems. Network engineers often need to evaluate network performance under various conditions and configurations. The mtr command’s ability to provide detailed, real-time data about network routes makes it an ideal tool for this purpose.

Exploring Related Concepts

While mastering the mtr command is a significant step, it’s also beneficial to explore related concepts. For instance, understanding network security principles can help you identify potential security vulnerabilities in your network. Similarly, learning about network performance optimization can provide insights into improving your network’s efficiency and reliability.

Further Resources for Mastering Network Diagnostics

To deepen your understanding of network diagnostics and related concepts, here are some resources you might find helpful:

  • The TCP/IP Guide: A comprehensive guide to TCP/IP protocols and the internet. It’s a great resource for understanding the underlying principles of network communications.

  • Cisco Networking Academy: Offers a range of courses on network engineering, including network security and performance optimization.

  • Linux Networking-HowTo: A detailed guide on networking in the Linux environment. It provides in-depth information on various networking commands, including mtr, and their usage.

By exploring these resources and continuously learning, you can enhance your skills in network diagnostics and become a proficient user of the mtr command.

Wrapping Up: Linux Networking and ‘mtr’

In this comprehensive guide, we’ve navigated the world of network diagnostics using the mtr command in Linux. This tool, which combines the functionality of the traceroute and ping commands, is a powerful ally for anyone looking to diagnose network issues.

We began with the basics, learning how to use the mtr command for simple network diagnostics. We then delved deeper, exploring intermediate and advanced usage of mtr, including different options and flags that can be used to customize the command’s functionality.

Along our journey, we tackled common challenges that you might encounter when using the mtr command, such as ‘Network is unreachable’ errors and problems with packet loss. For each issue, we provided solutions and workarounds to ensure a smooth network diagnostic process.

We also explored alternative approaches to network diagnostics, comparing the mtr command with other tools like traceroute and ping. Here’s a quick comparison of these methods:

MethodProsCons
MTRComprehensive, real-time dataMay require root privileges
TracerouteDetailed route informationDoes not provide continuous output
PingSimple connectivity and latency checksDoes not provide route information

Whether you’re just starting out with the mtr command or looking to advance your network diagnostic skills, we hope this guide has equipped you with the knowledge and confidence to use the mtr command effectively.

The ability to diagnose network issues is a vital skill in today’s interconnected world. With the mtr command in your toolkit, you’re well on your way to mastering network diagnostics. Happy troubleshooting!