This guide will teach you how to use MTR (My Traceroute) and Traceroute to diagnose network connectivity issues, identify latency points, and analyze the quality of your network connection.
📋 Prerequisites
- A VPS server with root or sudo access
- An active SSH connection
- Ubuntu/Debian (commands are adapted for these distributions)
🔧 Installation
Install Traceroute (basic tool)
Bash# On Ubuntu/Debian sudo apt update sudo apt install traceroute -y
Install MTR (advanced tool)
MTR combines the functionalities of ping and traceroute into a single powerful tool.
Bash# On Ubuntu/Debian sudo apt update sudo apt install mtr-tiny -y # For the full version with graphical interface (optional) sudo apt install mtr -y
Verify Installation
Bash# Verify that traceroute is installed traceroute --version # Verify that MTR is installed mtr --version
🛠️ Using Traceroute
Basic Command
Bash# Traceroute to a destination traceroute google.com # Traceroute to an IP traceroute 8.8.8.8 # Limit the number of hops (default 30) traceroute -m 20 google.com # Specify timeout in seconds traceroute -w 5 google.com
Useful Options
Bash# Use UDP (default) traceroute -U google.com # Use TCP (more reliable) traceroute -T google.com # Use ICMP (like ping) traceroute -I google.com # Don't resolve DNS names (faster) traceroute -n google.com
Example Output
traceroute to google.com (142.250.185.14), 30 hops max, 60 byte packets
1 10.0.0.1 (10.0.0.1) 0.123 ms 0.089 ms 0.067 ms
2 192.168.1.1 (192.168.1.1) 5.234 ms 5.189 ms 5.145 ms
3 * * *
4 8.8.8.8 (8.8.8.8) 12.456 ms 12.389 ms 12.334 ms
...
🚀 Using MTR (Recommended)
MTR is more powerful because it sends packets continuously and calculates statistics in real-time.
Basic Command
Bash# MTR in interactive mode (recommended) mtr google.com # MTR with report (non-interactive) mtr --report google.com # MTR with 10 test packets mtr --report --report-cycles 10 google.com # MTR to an IP mtr --report 8.8.8.8
Advanced Options
Bash# Specify the number of packets to send mtr --report --report-cycles 50 google.com # Use TCP instead of ICMP mtr --tcp --port 80 google.com # Use UDP mtr --udp --port 53 8.8.8.8 # Don't resolve DNS names mtr --no-dns google.com # Interval between packets (in seconds) mtr --interval 2 google.com # Packet size (in bytes) mtr --psize 64 google.com
MTR Interactive Mode
When you launch mtr without the --report option, you enter interactive mode:
- d : Show/hide detailed statistics
- n : Enable/disable DNS mode (name resolution)
- r : Reset statistics
- s : Change packet size
- j : Change interval between packets
- q : Quit MTR
📊 Interpreting Results
Normal Latency
- < 50 ms : Excellent, local network or very close
- 50-100 ms : Good, regional connection
- 100-200 ms : Acceptable, intercontinental connection
- > 200 ms : High, may cause problems
Packet Loss
- 0% : Perfect
- < 1% : Normal for an Internet connection
- 1-5% : Acceptable but may cause problems
- > 5% : Problematic, investigation required
Meaning of Asterisks (*)
In traceroute, a * means:
- A single * instead of a time : The router did not respond to that specific packet
- *Three consecutive 's : The router did not respond at all (timeout or firewall filter)
🎯 Use Cases
Diagnosing High Latency
Bash# Test to Google DNS mtr --report --report-cycles 30 8.8.8.8 # Test to Cloudflare DNS mtr --report --report-cycles 30 1.1.1.1 # Identify the problematic hop mtr --report --report-cycles 50 your-domain.com
Diagnosing Packet Loss
Bash# Test with TCP to bypass ICMP filters mtr --tcp --port 443 --report --report-cycles 50 google.com # Test to a specific server mtr --report --report-cycles 100 your-server.com
Test from Your VPS to Your Location
Bash# Test to your public IP address # Get your public IP first curl ifconfig.me # Then test from your VPS mtr --report --report-cycles 30 YOUR_PUBLIC_IP
🔍 Troubleshooting Common Problems
Problem: High Latency on a Specific Hop
If you see high latency on an intermediate hop:
Bash# Test with different protocols mtr --tcp --port 443 --report google.com mtr --udp --port 53 --report 8.8.8.8 mtr --report google.com
Important: High latency on an intermediate hop may be normal if that router doesn't respond quickly to diagnostic requests, but the final latency remains good.
Problem: Significant Packet Loss
If you see high packet loss:
Bash# Test with more packets to confirm mtr --report --report-cycles 100 destination.com # Test with TCP if ICMP is filtered mtr --tcp --port 80 --report --report-cycles 50 destination.com
Warning: If packet loss appears on all hops, the problem is likely on your VPS or your local connection. If it appears only on a specific hop, the problem is on the network between your VPS and the destination.
Problem: Repeated Timeouts
Bash# Increase timeout mtr --timeout 10 --report destination.com # Test with different protocols mtr --tcp --port 443 --timeout 10 --report destination.com
📝 Useful Commands
Complete Diagnostic Script
Create a script to test multiple destinations:
Bash#!/bin/bash echo "=== MTR Test to Google DNS ===" mtr --report --report-cycles 30 8.8.8.8 echo -e "\n=== MTR Test to Cloudflare DNS ===" mtr --report --report-cycles 30 1.1.1.1 echo -e "\n=== MTR Test to your domain ===" mtr --report --report-cycles 30 your-domain.com
Save Results
Bash# Save report to a file mtr --report --report-cycles 30 google.com > mtr-report-$(date +%Y%m%d).txt # With CSV format mtr --report --report-cycles 30 --csv google.com > mtr-report.csv
✅ Best Practices
- Use MTR rather than traceroute : MTR provides more complete statistics
- Test multiple destinations : Compare results to different servers
- Run multiple tests : Networks can vary, run multiple tests at different times
- Use TCP if ICMP is filtered : Some routers filter ICMP but not TCP
- Interpret results correctly : High latency on an intermediate hop is not always a problem if the final latency is good
🆘 Troubleshooting
MTR Doesn't Display Correctly
Bash# If MTR doesn't work in interactive mode, use report mode mtr --report destination.com # Check MTR version mtr --version
Error "mtr: command not found"
Bash# Reinstall MTR sudo apt update sudo apt install mtr-tiny -y # Or install the full version sudo apt install mtr -y
All Results Show Asterisks
If all hops show *, it may mean:
Bash# Your firewall is blocking ICMP # Test with TCP instead mtr --tcp --port 443 --report destination.com # Check firewall rules sudo ufw status sudo iptables -L
📚 Additional Resources
❓ Frequently Asked Questions
Q: What is the difference between Traceroute and MTR?
A: Traceroute sends a few packets and displays results. MTR sends packets continuously and calculates statistics in real-time, which is more useful for diagnosis.
Q: Why do some hops show asterisks?
A: This means the router did not respond. This can be due to a firewall filter, router configuration, or simply that the router doesn't respond to diagnostic requests.
Q: Should I worry about high latency on an intermediate hop?
A: Not necessarily. If the final latency to the destination is good, high latency on an intermediate hop may be normal. It's the final latency that really matters.
Q: How do I interpret packet loss in MTR?
A: Packet loss < 1% is normal. Between 1-5%, it's acceptable but may cause problems. Beyond 5%, it's problematic and requires investigation.