Tracerouteリファレンス
Linux、macOS、Windows向けの完全なtracerouteコマンドリファレンスです。
コマンド
traceroute <host>フラグ
| フラグ | 説明 |
|---|---|
| -n | Do 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) |
| -I | Use ICMP ECHO instead of UDP |
| -T | Use TCP SYN (requires root) |
| -p <port> | Destination port for UDP/TCP |
| -i <iface> | Use specified network interface |
| -s <src> | Use specified source address |
| -4 / -6 | Force IPv4 or IPv6 |
使用例
traceroute google.comBasic traceroute to a host
traceroute -n 8.8.8.8Traceroute without DNS resolution
traceroute -m 15 example.comLimit to 15 hops maximum
traceroute -I google.comUse ICMP instead of UDP
sudo traceroute -T -p 80 example.comTCP 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.