mtr - Linux


Overview

The mtr command (My traceroute) is a network diagnostic tool that combines the functions of the traceroute and ping commands into one tool. It effectively provides a continuous traceroute, showing real-time statistics on the network path and performance between the host machine and the specified target. Suitable for diagnosing network connections and paths, mtr is invaluable for network administrators and engineers to troubleshoot and monitor network issues.

Syntax

mtr [options] [destination]
  • destination can be a hostname or an IP address.

Options/Flags

  • -c, --report-cycles COUNT: Set the number of pings sent to determine the connection quality. Default is indefinite until stopped.
  • -r, --report: Generates a report that is more suited for automated processing.
  • -s, --psize PACKETSIZE: Specifies the size of the probing packet. The default is 64 bytes.
  • -t, --curses: Use terminal-based output even if X11 is available.
  • -n, --no-dns: Displays numeric IP addresses only and does not resolve host names.
  • -b, --show-ip: Shows both the IP address and the hostname in the output.
  • -i, --interval SECONDS: Interval between ping cycles; default is 1 second.
  • -w, --report-wide: Generates a wide report that includes more statistics.
  • -a, --aslookup: Performs AS lookup and includes the information in the output.
  • -p, --split: Use split-screen mode for asynchronous monitoring.
  • -g, --gtk: Opens the GTK+ graphical interface if available.

Examples

  1. Basic Usage: To start an mtr trace to example.com:
    mtr example.com
    
  2. Generate a Report: To generate a simple text report after 10 cycles to example.com:
    mtr -r -c 10 example.com
    
  3. Non-stop Monitoring Using Specific Packet Size:
    mtr -s 120 -n example.com
    

Common Issues

  • Insufficient Privileges: Running mtr without sufficient privileges might result in incomplete data as some networks reject or incorrectly handle ICMP packets.

    • Solution: Run mtr with root privileges using sudo.
  • DNS Issues: Sometimes, mtr may not resolve hostnames due to DNS configuration errors.

    • Solution: Use the -n flag to check IP addresses directly.
  • High Latency: Misinterpreting results where normal network variations appear as issues.

    • Workaround: Run multiple tests at different times to verify.

Integration

Combine mtr with cron to monitor and log network performance over time.

# Edit cron jobs
crontab -e
# Add a new job to run mtr every hour and log the output
0 * * * * mtr -r -c 30 example.com >> ~/mtr-logs.txt
  • traceroute: Traces the route packets take to a network host.
  • ping: Tests reachability of hosts by sending ICMP echo requests.
  • netstat: Displays network connections, routing tables, and interface statistics.

Further documentation is available through the man page (man mtr) or the official MTR GitHub repository.