mtr

networkingLinux/Unix
The mtr command is one of the most frequently used commands in Linux/Unix-like operating systems. mtr Network diagnostic tool combining ping and traceroute

Quick Reference

Command Name:

mtr

Category:

networking

Platform:

Linux/Unix

Basic Usage:

mtr [options] [arguments]

Common Use Cases

    Syntax

    mtr [options] hostname

    Options

    Option Description
    -4 Use IPv4 only
    -6 Use IPv6 only
    -c COUNT Set the number of pings sent to each hop
    -f FIRST_TTL Set the first TTL to use, default is 1
    -m MAX_TTL Set the maximum number of hops (TTL to use), default is 30
    -s PACKETSIZE Set the packet size used for probing
    -B NUM Set the socket buffer size used for probing
    -i INTERVAL Set the probe interval in seconds, default is 1 second
    -G GRACETIME Set the number of seconds to wait for responses after the final request
    -Q TOS Set the Type of Service (TOS) value in IPv4 packets
    -e Display both IP numbers and host names
    -n Do not resolve hostnames, show IP addresses only
    -b Show both hostname and IP address
    -u Use UDP instead of ICMP packets
    -T Use TCP instead of ICMP packets
    -P PORT Set the target port number for TCP/UDP scans
    -Z TIMEOUT Set the initial probe timeout in seconds
    -r Bypass normal routing tables and send directly to a host
    -w Use wide report format showing both hostnames and IP addresses
    -z Display packets with timestamps
    --report Output a report after the specified number of pings
    --report-cycles COUNT Set the number of pings for the report
    --json Output results in JSON format
    --csv Output results in CSV format
    --xml Output results in XML format
    --aslookup Display the AS number (Autonomous System)
    --displaymode MODE Set the display mode (0 for terminal, 1 for curses)
    -o FIELDS Specify which fields to display (e.g., "LSD NBAW")

    Field Specifiers for -o Option:

    Letter Field
    L Loss ratio
    D Dropped packets
    R Received packets
    S Sent packets
    N Newest RTT (last packet)
    B Best (minimum) RTT
    A Average RTT
    W Worst (maximum) RTT
    V Standard deviation
    G Geometric mean
    J Current jitter
    M Jitter mean (average)
    X Jitter standard deviation
    I Interarrival jitter

    Examples

    How to Use These Examples

    The examples below show common ways to use the mtr command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Basic Examples Basic
    mtr google.com
    Start an interactive mtr session to google.com.
    mtr --report google.com
    Generate a single report showing network path to google.com.
    # Advanced Examples Advanced
    mtr -c 5 --report google.com Generate a report after sending 5 pings to each hop. mtr -T -P 443 example.com Use TCP instead of ICMP and target port 443 (HTTPS). mtr -w example.com Run mtr in wide report mode showing hostnames and IP addresses. mtr -z example.com Display packets with timestamps. mtr -b example.com Show both the hostname and IP address for each hop. mtr --aslookup example.com Show the Autonomous System (AS) number for each hop. mtr -4 example.com Force IPv4 only. mtr -6 example.com Force IPv6 only. mtr -o "LSD NBAW V" example.com Customize output columns (Loss%, Sent, Destination, etc).

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    The 'mtr' (My Traceroute) command is a powerful network diagnostic tool that combines the functionality of the 'traceroute' and 'ping' utilities in a single, interactive interface. It continuously monitors the connection between your computer and a target host, providing real-time statistics about each network hop along the path. Key features of the mtr command: 1. Continuous Monitoring: Unlike traceroute which runs once and exits, mtr continuously sends packets and updates statistics in real time, allowing you to observe network behavior over time. 2. Comprehensive Statistics: For each hop in the network path, mtr displays detailed metrics including packet loss, response times (minimum, average, maximum), and standard deviation, giving a complete picture of network performance. 3. Multiple Protocols: mtr can use different protocols for probing, including ICMP (default), UDP, and TCP, which helps diagnose issues where certain types of traffic might be filtered or handled differently. 4. Interactive Interface: The default ncurses-based interface updates in real-time and allows for interaction, such as pausing the display or sorting results. 5. Reporting Modes: Besides the interactive mode, mtr can generate single reports after a specified number of packets, which is useful for sharing results or automation. 6. Export Formats: Results can be exported in various formats including plain text, CSV, JSON, and XML, facilitating integration with other tools or analysis software. 7. Network Path Visualization: By showing each hop in the path between source and destination, mtr helps identify exactly where in the network problems are occurring. Common use cases for mtr include: - Troubleshooting network connectivity issues by identifying which hops are experiencing packet loss or high latency - Monitoring network stability over time to identify intermittent problems - Comparing network paths between different destinations or from different source locations - Validating network changes or performance improvements - Documenting network behavior for support cases with ISPs or service providers - Detecting routing issues, such as suboptimal paths or routing loops - Benchmarking network performance between different locations While ping provides basic connectivity testing and traceroute shows the network path, mtr's combination of these features with continuous monitoring and statistical analysis makes it significantly more powerful for diagnosing complex network issues. Its ability to quickly identify problematic network segments and quantify their impact makes it an essential tool for network administrators and technical support personnel. It's worth noting that mtr requires root privileges on some systems to send certain types of packets, particularly when using ICMP. Modern versions of mtr typically install as setuid root or have capabilities set to allow non-root users to run it effectively.

    Related Commands

    These commands are frequently used alongside mtr or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the mtr command works in different scenarios.

    $ mtr
    View All Commands