본문으로 건너뛰기
🛠️ToolsShed

Traceroute 레퍼런스

Linux, macOS, Windows를 위한 완전한 traceroute 명령어 레퍼런스입니다.

명령어

traceroute <host>

플래그

플래그설명
-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

예제

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

작동 원리

Traceroute는 컴퓨터에서 대상 호스트까지의 네트워크 경로를 매핑합니다. TTL(Time To Live) 값을 증가시킨 패킷을 보내고 각 라우터의 응답을 기록하여 각 홉에서의 IP 주소와 응답 시간을 표시합니다. 이는 네트워크 연결 문제를 진단하고 라우팅 경로를 이해하는 데 도움이 됩니다.

이 도구 소개

트레이스라우트(traceroute)는 컴퓨터에서 목적지 호스트로 가는 데이터 패킷이 통과하는 네트워크 경로를 매핑하는 진단 도구로, 각 중간 라우터 홉과 각 홉에 도달하는 데 걸리는 시간을 표시합니다. 인터넷을 통해 데이터가 어떻게 이동하는지 이해하는 것은 연결 문제를 진단하거나, 레이턴시 문제를 파악하거나, 라우팅 동작을 이해해야 하는 네트워크 관리자, 개발자, IT 전문가에게 중요합니다. 이 Traceroute Reference는 Linux, macOS 및 Windows 시스템에 대한 완전한 명령 가이드를 제공하며, 각 플랫폼의 구문, 옵션 및 실제 예제를 포함합니다.

운영 체제별 트레이스라우트 명령을 찾아보고, 패킷 크기 조정, 최대 홉 변경, 특정 포트 번호 설정, 또는 타임아웃 값 구성 등 사용 가능한 옵션에 대한 상세 설명을 탐색하기만 하면 됩니다. 원격 서버로의 느린 연결을 문제 해결하거나, 패킷이 특정 홉에서 손실되는 이유를 조사하거나, 인프라 계획을 위해 네트워크 토폴로지를 문서화하고 있다면, 이 참고 자료는 불필요한 복잡성 없이 실용적인 지침을 제공합니다.

네트워크 전문가, 시스템 관리자, 사이버 보안 전문가 및 클라우드 엔지니어 모두 진단 도구 키트의 일부로 트레이스라우트를 사용합니다. 이 도구는 신뢰할 수 있는 네트워크 연결을 유지하거나, 프로덕션 시스템을 지원하거나, 다중 홉 네트워크 환경에서 문제를 조사할 책임이 있는 모든 사람에게 필수적입니다.

자주 묻는 질문

코드 구현

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.