How to Use the ‘mtr’ Command in Linux
Learn how to troubleshoot network issues like a pro with Linux's mtr command.
The mtr
command, short for “My Traceroute,” is a powerful network diagnostic tool that combines the functionality of both the traceroute
and ping
commands. By sending packets to a specified destination, it provides insights into the network path and helps identify potential bottlenecks or failures. Similar to tools like traceroute
, ping
, and pathping
, the mtr
command offers a more comprehensive view of the network’s performance.
System administrators and network engineers find the mtr
command handy for troubleshooting network issues. Whether you’re monitoring the stability of a connection or diagnosing a complex network problem, the mtr
command can be used alongside commands like ifconfig
or netstat
to provide a detailed analysis.
How to Install the mtr
Command
You may need to install the mtr
package if it’s not already included in your Linux distribution. Here’s how you can install and uninstall it on some common distributions:
For Debian-based systems (like Ubuntu):
To install mtr
you can use the following command:
sudo apt-get update sudo apt-get install mtr
To uninstall mtr
later, you can use:
sudo apt-get remove --purge mtr
For Red Hat-based systems (like Fedora):
To install mtr
you can use:
sudo dnf install mtr
To uninstall mtr
later, you can use:
sudo dnf remove mtr
For Arch-based systems:
To install mtr
you can use:
sudo pacman -S mtr
To uninstall mtr
later, you can use:
sudo pacman -R mtr
How to Use mtr
1. Basic Usage
Syntax: mtr <hostname>
Explanation: Traces the route to a given hostname or IP address.
Example: mtr example.com
Output:
Host Loss% Snt Last Avg Best Wrst StDev 1. router.local 0.0% 10 1.2 1.3 1.1 1.5 0.1 2. isp-gateway 0.0% 10 2.3 2.4 2.2 2.6 0.1 3. example.com 0.0% 10 10.5 10.6 10.4 10.8 0.1
This output shows the route to example.com
, with three hops. It provides details on packet loss, number of sent packets, and latency statistics for each hop.
2. Using ICMP Instead of UDP
Syntax: mtr --icmp <hostname>
Explanation: Traces the route using ICMP ECHO
instead of UDP
datagrams.
Example: mtr --icmp example.com
Output:
Host Loss% Snt Last Avg Best Wrst StDev 1. router.local 0.0% 10 1.1 1.2 1.0 1.3 0.1 2. isp-gateway 0.0% 10 2.2 2.3 2.1 2.5 0.1 3. example.com 0.0% 10 10.4 10.5 10.3 10.6 0.1
This command uses ICMP ECHO
for tracing, which might provide different results compared to the default UDP
, especially if certain firewalls or filters are in place.
3. Showing the AS (Autonomous System) Number
Syntax: mtr --aslookup <hostname>
Explanation: Traces the route and displays the ASN
(AS number) for each hop.
Example: mtr --aslookup example.com
Output:
Host Loss% Snt Last Avg Best Wrst StDev ASN 1. router.local 0.0% 10 1.2 1.3 1.1 1.5 0.1 AS12345 2. isp-gateway 0.0% 10 2.3 2.4 2.2 2.6 0.1 AS12345 3. example.com 0.0% 10 10.5 10.6 10.4 10.8 0.1 AS67890
This output includes the Autonomous System (AS) number for each hop, which can provide insights into the ownership and control of the network infrastructure along the path to the target.
4. Using TCP Instead of UDP
Syntax: mtr --tcp <hostname>
Explanation: Traces the route using TCP SYN
packets instead of UDP.
Example: mtr --tcp example.com
Output:
Host Loss% Snt Last Avg Best Wrst StDev 1. router.local 0.0% 10 1.4 1.5 1.3 1.6 0.1 2. isp-gateway 0.0% 10 2.5 2.6 2.4 2.7 0.1 3. example.com 0.0% 10 10.7 10.8 10.5 11.0 0.1
This command uses TCP SYN
packets for tracing, which can be useful if UDP
is being filtered or blocked along the route.
5. Specifying the Number of Pings
Syntax: mtr -c <count> <hostname>
Explanation: Sends a specified number of pings to each hop.
Example: mtr -c 5 example.com
Output:
Host Loss% Snt Last Avg Best Wrst StDev 1. router.local 0.0% 5 1.2 1.3 1.1 1.5 0.1 2. isp-gateway 0.0% 5 2.3 2.4 2.2 2.6 0.1 3. example.com 0.0% 5 10.5 10.6 10.4 10.8 0.1
This command sends only 5 pings to each hop, allowing for a quicker analysis of the route.
6. Displaying the Report at the End
Syntax: mtr --report <hostname>
Explanation: Runs mtr
in report mode, which sends a sequence of pings to each hop and then displays a report at the end.
Example: mtr --report example.com
Output:
HOST: localhost Loss% Snt Last Avg Best Wrst StDev 1. router.local 0.0% 10 1.2 1.3 1.1 1.5 0.1 2. isp-gateway 0.0% 10 2.3 2.4 2.2 2.6 0.1 3. example.com 0.0% 10 10.5 10.6 10.4 10.8 0.1
This command is useful for generating a single report at the end of the test, rather than continuously updating the display. It’s often used for logging or scripting purposes.
More Linux commands:
Directory Operations | rmdir · cd · pwd · exa · ls |
File Operations | cat · cp · dd · less · touch · ln · rename · more · head |
File System Operations | chown · mkfs · locate |
Networking | ping · curl · wget · iptables · mtr |
Search and Text Processing | find · grep · sed · whatis · ripgrep · fd · tldr |
System Information and Management | env · history · top · who · htop · glances · lsof |
User and Session Management | screen · su · sudo · open |