Skip to content
🛠️ToolsShed

Traceroute Reference

Complete traceroute command reference for Linux, macOS, and Windows.

Command

traceroute <host>

Flags

FlagDescription
-nDo not resolve hostnames (faster)
-m <hops>Set maximum hops (default: 30)
-w <sec>Wait time per probe (default: 5s)
-q <n>Number of probes per hop (default: 3)
-IUse ICMP ECHO instead of UDP
-TUse TCP SYN (requires root)
-p <port>Destination port for UDP/TCP
-i <iface>Use specified network interface
-s <src>Use specified source address
-4 / -6Force IPv4 or IPv6

Examples

traceroute google.com

Basic traceroute to a host

traceroute -n 8.8.8.8

Traceroute without DNS resolution

traceroute -m 15 example.com

Limit to 15 hops maximum

traceroute -I google.com

Use ICMP instead of UDP

sudo traceroute -T -p 80 example.com

TCP traceroute on port 80

How It Works

Traceroute maps the network path from your computer to a destination host. It sends packets with increasing TTL (Time To Live) values and records each router's response, showing the IP address and response time at each hop. This helps diagnose network connectivity issues and understand routing paths.

About this tool

Traceroute is a diagnostic tool that maps the network path taken by data packets traveling from your computer to a destination host, showing each intermediate router hop and the time it takes to reach each one. Understanding how data travels across the internet is crucial for network administrators, developers, and IT professionals who need to diagnose connectivity issues, identify latency problems, or understand routing behavior. This Traceroute Reference provides a complete command guide for Linux, macOS, and Windows systems, covering syntax, options, and real-world examples for each platform.

Simply look up the traceroute command for your operating system and explore the detailed explanations of available options—whether you need to adjust the packet size, change the maximum hops, set specific port numbers, or configure timeout values. Whether you're troubleshooting a slow connection to a remote server, investigating why packets are being dropped at a particular hop, or documenting network topology for infrastructure planning, this reference delivers practical guidance without unnecessary complexity.

Network professionals, system administrators, cybersecurity specialists, and cloud engineers all rely on traceroute as part of their diagnostic toolkit. This tool is essential for anyone responsible for maintaining reliable network connectivity, supporting production systems, or investigating issues in multi-hop network environments.

Frequently Asked Questions

Code Implementation

import subprocess
import platform
import re

def traceroute(host: str, max_hops: int = 30) -> list[dict]:
    """Run traceroute and parse output."""
    system = platform.system()
    if system == "Windows":
        cmd = ["tracert", "-h", str(max_hops), host]
    else:
        cmd = ["traceroute", "-m", str(max_hops), host]

    result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
    lines = result.stdout.splitlines()
    hops = []
    for line in lines[1:]:  # skip header
        # Parse hop number and RTT values
        match = re.match(r"\s*(\d+)\s+(.+)", line)
        if match:
            hop_num = int(match.group(1))
            rest = match.group(2)
            times = re.findall(r"([\d.]+)\s*ms", rest)
            hostname = re.search(r"([\w.-]+)\s+\(", rest)
            hops.append({
                "hop": hop_num,
                "host": hostname.group(1) if hostname else "*",
                "times_ms": [float(t) for t in times],
            })
    return hops

hops = traceroute("google.com", max_hops=15)
for hop in hops:
    avg = sum(hop["times_ms"]) / len(hop["times_ms"]) if hop["times_ms"] else None
    avg_str = f"{avg:.1f} ms" if avg else "*"
    print(f"{hop['hop']:2d}  {hop['host']:<40} {avg_str}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.