How to trace network path → traceroute or mtr
How to Trace Network Path → traceroute \ or mtr \
Table of Contents
1. [Introduction](#introduction)
2. [Prerequisites](#prerequisites)
3. [Understanding Network Path Tracing](#understanding-network-path-tracing)
4. [Traceroute Command Guide](#traceroute-command-guide)
5. [MTR Command Guide](#mtr-command-guide)
6. [Practical Examples and Use Cases](#practical-examples-and-use-cases)
7. [Comparing Traceroute vs MTR](#comparing-traceroute-vs-mtr)
8. [Advanced Options and Techniques](#advanced-options-and-techniques)
9. [Troubleshooting Common Issues](#troubleshooting-common-issues)
10. [Best Practices](#best-practices)
11. [Security Considerations](#security-considerations)
12. [Conclusion](#conclusion)
Introduction
Network path tracing is a fundamental diagnostic technique that reveals the route data packets take from your computer to a destination host across the internet. This comprehensive guide explores two essential command-line tools: `traceroute` and `mtr` (My Traceroute), which help network administrators, developers, and IT professionals identify network bottlenecks, routing issues, and connectivity problems.
Whether you're troubleshooting slow website loading times, diagnosing network outages, or analyzing network performance, understanding how to effectively use traceroute and mtr commands is crucial for modern network management. This article provides detailed instructions, practical examples, and expert insights to help you master these powerful network diagnostic tools.
Prerequisites
Before diving into network path tracing, ensure you have the following:
System Requirements
- Operating System: Linux, macOS, or Windows with appropriate tools installed
- Network Access: Active internet connection
- Command Line Access: Terminal (Linux/macOS) or Command Prompt/PowerShell (Windows)
- Administrative Privileges: Some operations may require elevated permissions
Software Installation
Linux Systems
Most Linux distributions include traceroute by default. For mtr:
```bash
Ubuntu/Debian
sudo apt-get update && sudo apt-get install mtr-tiny
CentOS/RHEL/Fedora
sudo yum install mtr
or for newer versions
sudo dnf install mtr
```
macOS
```bash
Using Homebrew
brew install mtr
Traceroute is pre-installed on macOS
```
Windows
```powershell
Windows has tracert built-in (equivalent to traceroute)
For mtr functionality, use WinMTR or install via Chocolatey
choco install winmtr
```
Basic Networking Knowledge
- Understanding of IP addresses and domain names
- Basic knowledge of network protocols (TCP/IP, ICMP)
- Familiarity with command-line interfaces
Understanding Network Path Tracing
Network path tracing works by sending packets with incrementally increasing Time-To-Live (TTL) values. Each router along the path decreases the TTL by one, and when it reaches zero, the router sends back an ICMP "Time Exceeded" message, revealing its identity and location in the network path.
How It Works
1. Initial Packet: Send a packet with TTL=1 to the destination
2. First Hop Response: The first router decreases TTL to 0 and responds with its IP address
3. Increment TTL: Send another packet with TTL=2
4. Continue Process: Repeat until reaching the destination or maximum hops
Key Metrics Measured
- Hop Number: Position of each router in the path
- IP Address/Hostname: Identity of each intermediate router
- Response Time: Round-trip time for each hop (usually shown in milliseconds)
- Packet Loss: Percentage of packets that don't receive responses
Traceroute Command Guide
Basic Syntax
```bash
traceroute [options]
```
Common Options
| Option | Description | Example |
|--------|-------------|---------|
| `-n` | Show IP addresses instead of hostnames | `traceroute -n google.com` |
| `-m ` | Set maximum number of hops | `traceroute -m 15 google.com` |
| `-w ` | Set timeout for responses (seconds) | `traceroute -w 5 google.com` |
| `-q ` | Number of queries per hop | `traceroute -q 1 google.com` |
| `-p ` | Use specific port for UDP traces | `traceroute -p 80 google.com` |
| `-I` | Use ICMP instead of UDP | `traceroute -I google.com` |
| `-T` | Use TCP SYN for tracing | `traceroute -T google.com` |
Basic Traceroute Example
```bash
$ traceroute google.com
traceroute to google.com (172.217.164.110), 30 hops max, 60 byte packets
1 gateway (192.168.1.1) 1.234 ms 1.456 ms 1.789 ms
2 10.0.0.1 (10.0.0.1) 12.345 ms 13.456 ms 14.567 ms
3 isp-router.net (203.0.113.1) 25.123 ms 26.234 ms 27.345 ms
4 *
5 google-router.net (8.8.8.8) 45.678 ms 46.789 ms 47.890 ms
6 google.com (172.217.164.110) 48.901 ms 49.012 ms 50.123 ms
```
Understanding Traceroute Output
Each line represents a hop in the network path:
- Hop Number: Sequential number (1, 2, 3, etc.)
- Hostname/IP: Router identification
- Three Time Values: Response times for three probe packets
- Asterisks (*): Indicate timeouts or blocked responses
MTR Command Guide
MTR (My Traceroute) combines the functionality of traceroute and ping, providing continuous monitoring and statistical analysis of network paths.
Basic Syntax
```bash
mtr [options]
```
Common MTR Options
| Option | Description | Example |
|--------|-------------|---------|
| `-r` | Report mode (non-interactive) | `mtr -r google.com` |
| `-c ` | Number of pings to send | `mtr -c 10 google.com` |
| `-n` | Show IP addresses only | `mtr -n google.com` |
| `-b` | Show both hostnames and IP addresses | `mtr -b google.com` |
| `-i ` | Set interval between pings | `mtr -i 2 google.com` |
| `-s ` | Set packet size | `mtr -s 1000 google.com` |
| `--tcp` | Use TCP SYN packets | `mtr --tcp google.com` |
| `--udp` | Use UDP packets | `mtr --udp google.com` |
Basic MTR Example
```bash
$ mtr -r -c 10 google.com
Start: 2024-01-15T10:30:00+0000
HOST: mycomputer Loss% Snt Last Avg Best Wrst StDev
1.|-- gateway 0.0% 10 1.2 1.3 1.1 1.6 0.2
2.|-- 10.0.0.1 0.0% 10 12.3 13.1 11.8 15.2 1.1
3.|-- isp-router.net 0.0% 10 25.1 26.3 24.5 29.8 1.8
4.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0
5.|-- google-router.net 0.0% 10 45.7 46.2 44.9 48.3 1.2
6.|-- google.com 0.0% 10 48.9 49.5 47.8 52.1 1.4
```
Understanding MTR Output
MTR provides comprehensive statistics:
- Loss%: Percentage of packet loss for each hop
- Snt: Number of packets sent
- Last: Most recent response time
- Avg: Average response time
- Best: Best (fastest) response time
- Wrst: Worst (slowest) response time
- StDev: Standard deviation of response times
Practical Examples and Use Cases
Example 1: Diagnosing Slow Website Performance
```bash
Check path to a slow-loading website
mtr -r -c 20 slowwebsite.com
Look for:
- High packet loss percentages
- Sudden increases in latency
- Timeouts at specific hops
```
Example 2: Identifying Network Bottlenecks
```bash
Use traceroute with ICMP for better firewall penetration
traceroute -I -n example.com
Compare with TCP traceroute
traceroute -T -p 80 example.com
```
Example 3: Monitoring Network Stability
```bash
Continuous monitoring with MTR
mtr -i 5 -c 100 criticalserver.com
Export results for analysis
mtr -r -c 50 server.com > network_analysis.txt
```
Example 4: Troubleshooting International Connectivity
```bash
Trace to international destination
traceroute -n -m 25 international-server.com
Look for:
- Submarine cable hops
- International gateway delays
- Routing through unexpected countries
```
Example 5: Testing Different Protocols
```bash
ICMP traceroute (often blocked by firewalls)
traceroute -I destination.com
TCP traceroute (more likely to succeed)
traceroute -T -p 443 destination.com
UDP traceroute (default, may be blocked)
traceroute destination.com
```
Comparing Traceroute vs MTR
When to Use Traceroute
- Quick Path Discovery: Fast identification of network route
- Simple Troubleshooting: Basic connectivity issue diagnosis
- Script Integration: Automated network testing scripts
- One-time Analysis: Single snapshot of network path
When to Use MTR
- Detailed Analysis: Comprehensive network performance statistics
- Continuous Monitoring: Long-term network stability assessment
- Performance Optimization: Identifying intermittent issues
- Quality Metrics: Detailed latency and loss statistics
Feature Comparison Table
| Feature | Traceroute | MTR |
|---------|------------|-----|
| Real-time updates | No | Yes |
| Statistical analysis | Basic | Comprehensive |
| Packet loss detection | Limited | Detailed |
| Continuous monitoring | No | Yes |
| Resource usage | Low | Moderate |
| Output format | Simple | Rich |
| Learning curve | Easy | Moderate |
Advanced Options and Techniques
Advanced Traceroute Techniques
Custom Packet Sizes
```bash
Test with larger packets to simulate real traffic
traceroute -I -s 1400 destination.com
```
Multiple Queries Per Hop
```bash
Increase reliability with more probes per hop
traceroute -q 5 destination.com
```
Custom Source Address
```bash
Specify source interface for multi-homed systems
traceroute -s 192.168.1.100 destination.com
```
Advanced MTR Techniques
JSON Output for Automation
```bash
Generate machine-readable output
mtr -r -c 10 --json destination.com
```
Custom Packet Types
```bash
Test with TCP packets to port 443
mtr --tcp -P 443 -c 20 destination.com
```
Bandwidth Testing
```bash
Test with various packet sizes
for size in 64 128 256 512 1024 1400; do
echo "Testing with packet size: $size"
mtr -r -c 5 -s $size destination.com
done
```
Combining Tools for Comprehensive Analysis
```bash
#!/bin/bash
Comprehensive network analysis script
TARGET=$1
echo "Network Analysis for: $TARGET"
echo "================================"
echo "1. Basic Traceroute:"
traceroute -n $TARGET
echo -e "\n2. MTR Analysis:"
mtr -r -c 10 $TARGET
echo -e "\n3. TCP Traceroute:"
traceroute -T -p 80 $TARGET
echo -e "\n4. Ping Statistics:"
ping -c 10 $TARGET
```
Troubleshooting Common Issues
Issue 1: Asterisks (*) in Traceroute Output
Problem: Seeing ` *` instead of router information
Possible Causes:
- Firewall blocking ICMP responses
- Router configured not to respond to traceroute
- Network congestion causing timeouts
Solutions:
```bash
Try TCP traceroute instead of UDP/ICMP
traceroute -T -p 80 destination.com
Increase timeout value
traceroute -w 10 destination.com
Use different packet types
traceroute -I destination.com # ICMP
traceroute -U destination.com # UDP
```
Issue 2: Permission Denied Errors
Problem: "Operation not permitted" or similar errors
Solutions:
```bash
Run with sudo for raw socket access
sudo traceroute destination.com
Use unprivileged mode for MTR
mtr --udp destination.com
```
Issue 3: Inconsistent Results
Problem: Different results on repeated runs
Causes:
- Load balancing across multiple paths
- Dynamic routing changes
- Network congestion variations
Solutions:
```bash
Use MTR for statistical analysis
mtr -r -c 50 destination.com
Multiple traceroute runs
for i in {1..5}; do
echo "Run $i:"
traceroute destination.com
sleep 5
done
```
Issue 4: High Latency at Specific Hops
Problem: Sudden latency increases at certain routers
Analysis Steps:
1. Identify the problematic hop
2. Check if latency persists to subsequent hops
3. Verify with different packet types
```bash
Detailed analysis of specific hop
ping -c 20 [hop-ip-address]
mtr -r -c 30 [hop-ip-address]
```
Issue 5: Destination Unreachable
Problem: Traceroute stops before reaching destination
Diagnostic Steps:
```bash
Check if destination is reachable
ping destination.com
Try different protocols
traceroute -I destination.com
traceroute -T -p 443 destination.com
Check DNS resolution
nslookup destination.com
```
Best Practices
1. Choose the Right Tool for the Job
Use Traceroute When:
- Quick path identification needed
- Scripting and automation required
- System resources are limited
- Simple troubleshooting is sufficient
Use MTR When:
- Detailed performance analysis required
- Intermittent issues need investigation
- Statistical data is important
- Long-term monitoring is needed
2. Optimize Command Parameters
```bash
For quick diagnosis
traceroute -n -w 3 destination.com
For detailed analysis
mtr -r -c 30 -i 1 destination.com
For firewall-heavy environments
traceroute -T -p 443 destination.com
```
3. Interpret Results Correctly
Normal Patterns:
- Gradual latency increase with distance
- Consistent response times across runs
- Complete path to destination
Warning Signs:
- Sudden latency spikes
- High packet loss percentages
- Incomplete paths with timeouts
4. Document and Compare Results
```bash
Create baseline measurements
mtr -r -c 50 criticalserver.com > baseline_$(date +%Y%m%d).txt
Compare current performance
mtr -r -c 50 criticalserver.com > current_$(date +%Y%m%d).txt
diff baseline_.txt current_.txt
```
5. Consider Network Security
Security Implications:
- Traceroute reveals network topology
- May be blocked by security policies
- Can be used for reconnaissance
Mitigation Strategies:
- Use internal network documentation
- Implement rate limiting for ICMP
- Monitor for excessive traceroute activity
6. Automate Regular Monitoring
```bash
#!/bin/bash
Network monitoring cron job
TARGETS=("google.com" "cloudflare.com" "github.com")
LOGFILE="/var/log/network_monitoring.log"
for target in "${TARGETS[@]}"; do
echo "$(date): Testing $target" >> $LOGFILE
mtr -r -c 10 $target >> $LOGFILE
echo "---" >> $LOGFILE
done
```
7. Performance Optimization Tips
For Better Results:
- Run tests during different times of day
- Test from multiple source locations
- Use appropriate packet sizes for your use case
- Consider network load during testing
Resource Management:
```bash
Limit resource usage
nice -n 10 mtr -r -c 20 destination.com
Batch processing
echo "google.com cloudflare.com github.com" | xargs -n 1 -P 3 traceroute
```
Security Considerations
Network Information Disclosure
Traceroute and MTR reveal sensitive network information:
- Internal IP ranges
- Router configurations
- Network topology
- ISP infrastructure
Firewall and IDS Interactions
Many security systems treat traceroute as suspicious:
- Rate limiting may affect results
- Blocked ICMP responses are common
- TCP traceroute may trigger alerts
Best Security Practices
1. Use appropriate protocols for your environment
2. Respect rate limits and avoid excessive testing
3. Document legitimate use cases for security teams
4. Consider privacy implications when sharing results
```bash
Respectful testing approach
traceroute -q 1 -w 5 destination.com # Fewer queries, shorter timeout
```
Conclusion
Network path tracing using traceroute and mtr commands is an essential skill for anyone involved in network administration, troubleshooting, or performance optimization. These powerful tools provide invaluable insights into how data travels across networks, helping identify bottlenecks, routing issues, and connectivity problems.
Key Takeaways
1. Traceroute excels at quick path discovery and simple diagnostics
2. MTR provides comprehensive statistical analysis and continuous monitoring
3. Protocol selection (ICMP, UDP, TCP) significantly impacts results
4. Proper interpretation of results requires understanding network fundamentals
5. Security considerations must be balanced with diagnostic needs
Next Steps
To further enhance your network diagnostic capabilities:
1. Practice regularly with different destinations and network conditions
2. Combine tools for comprehensive analysis approaches
3. Automate monitoring for critical network paths
4. Study network protocols to better understand the underlying mechanisms
5. Explore advanced tools like Paris Traceroute for load-balanced networks
Additional Resources
For continued learning and advanced techniques:
- Network protocol documentation (RFC 792 for ICMP)
- Advanced networking courses and certifications
- Network monitoring and analysis tools
- Community forums and professional networking groups
By mastering these network path tracing techniques, you'll be well-equipped to diagnose and resolve network issues efficiently, ensuring optimal network performance and reliability in your environment.