內容目錄
什麼是 Trippy?
Trippy 是一款以 Rust 開發的開源網路診斷工具,它將傳統的 traceroute 與 ping 功能合而為一,並提供美觀的終端 TUI(Terminal User Interface)介面。專案由 fujiapple852 維護,在 GitHub 上已獲得超過 6,400 顆星,授權為 Apache 2.0。
簡單來說,Trippy 就是 mtr 的現代 Rust 替代品,功能更豐富、視覺更直觀。
核心功能概覽
- 多協定支援:ICMP、UDP、TCP,搭配 IPv4 / IPv6
- 互動式 TUI:即時顯示每個 hop 的延遲、封包遺失率、統計圖表
- 多目標同時追蹤:單一實例可同時 trace 多個目標(ICMP 模式)
- ECMP 路由策略:支援
classic、paris、dublin三種模式 - GeoIP 地圖:互動式世界地圖顯示路由地理位置
- DNS 查詢:支援系統 DNS、Google、Cloudflare 或自訂解析器,並可查詢 ASN 資訊
- 多種報表輸出:JSON、CSV、Markdown、Graphviz DOT 等格式
- 跨平台:Linux、macOS、Windows、BSD 系列皆支援
安裝方式
Linux(Debian / Ubuntu)
# Debian 13+ 可直接安裝
apt install trippy
# Ubuntu 22.04 / 24.04 透過 PPA
add-apt-repository ppa:fujiapple/trippy
apt update && apt install trippy
# Snap
snap install trippy
# Arch Linux
pacman -S trippy
macOS
brew install trippy
Windows
# WinGet
winget install trippy
# Scoop
scoop install trippy
# Chocolatey
choco install trippy
透過 Cargo(跨平台通用)
需先安裝 Rust 工具鏈(https://rustup.rs):
cargo install trippy --locked
Docker
docker run -it fujiapple/trippy
快速上手
安裝完成後,執行指令為 trip(注意:不是 trippy)。
# 最基本用法:追蹤到目標主機
sudo trip example.com
為什麼需要 sudo?
Trippy 預設使用 raw socket 發送 ICMP 封包,需要 root 權限。若不想使用 sudo,可啟用 unprivileged 模式(見下方說明)。
TUI 介面說明
啟動後會進入互動式 TUI,主要分為幾個區域:
- 上方表格:每個 hop 的詳細統計資料(sent、received、loss%、last、avg、best、worst、stddev、jitter)
- 右側圖表:RTT 歷史趨勢與頻率分佈圖
- 下方:互動式 RTT 折線圖,可縮放
- GeoIP 地圖:開啟後顯示路由世界地圖
常用鍵盤快捷鍵
| 按鍵 | 功能 |
|---|---|
q |
退出 |
f |
凍結 / 解凍 TUI |
r |
重置統計數據 |
k / j |
上 / 下移動 hop |
m |
展開地圖視圖 |
? |
顯示說明 |
常用指令範例
選擇追蹤協定
# 使用 UDP 協定
trip example.com -p udp
# 使用 TCP 協定
trip example.com -p tcp
# 使用 ICMP(預設)
trip example.com -p icmp
# 或使用別名
trip example.com --icmp
不需要 root 的 Unprivileged 模式
trip example.com --unprivileged
僅在部分平台支援(Linux 需核心允許 unprivileged ICMP socket)。
同時追蹤多個目標
trip example.com google.com cloudflare.com
僅限 ICMP 協定。
自訂 TTL 範圍
# 從第 3 hop 開始,最多追蹤到第 20 hop
trip example.com --first-ttl 3 --max-ttl 20
TCP 追蹤到指定 Port
# 追蹤 HTTPS(443 port)
trip example.com -p tcp -P 443
IPv6 追蹤
trip example.com -6
ECMP 路由策略(適用於負載平衡環境)
# 使用 dublin 策略,固定 source port 和 destination port
trip example.com -p udp -R dublin -S 5000 -P 3500
# 使用 paris 策略
trip example.com -p udp -R paris
paris和dublin策略可讓 Trippy 在 ECMP 負載平衡的網路中追蹤到一致的路徑,避免每次 trace 走不同的路徑。
DNS 查詢設定
# 使用 Google DNS
trip example.com -r google
# 使用 Cloudflare DNS
trip example.com -r cloudflare
# 同時顯示 ASN(自治系統號碼)資訊
trip example.com -r google -z
GeoIP 地理位置顯示
首先從 MaxMind 或 IPinfo 下載 .mmdb 檔案,然後:
trip example.com --geoip-mmdb-file GeoLite2-City.mmdb --tui-geoip-mode short
--tui-geoip-mode 可選 short、long、location、off。
生成報表
Trippy 可以在不顯示 TUI 的情況下直接輸出報表,適合用於自動化腳本或監控系統。
# 輸出 JSON 報表(收集 5 輪資料)
trip example.com -m json -C 5
# 輸出 CSV
trip example.com -m csv -C 5
# 美觀的文字表格
trip example.com -m pretty -C 5
# Markdown 格式
trip example.com -m markdown -C 5
# 輸出 Graphviz DOT 圖(TCP 協定)
trip example.com --tcp -m dot -C 5
# 輸出所有 tracing flows(UDP 協定)
trip example.com --udp -m flows -C 5
JSON 輸出範例結構:
{
"info": { "target": { "ip": "93.184.216.34", "hostname": "example.com" } },
"hops": [
{
"ttl": 1,
"hosts": [{ "ip": "192.168.1.1", "hostname": "router.local" }],
"loss_pct": 0.0,
"last_ms": 1.2,
"avg_ms": 1.5,
"best_ms": 1.0,
"worst_ms": 2.1,
"stddev_ms": 0.3
}
]
}
進階設定:設定檔
Trippy 支援透過 TOML 設定檔儲存你的偏好設定,省去每次輸入參數的麻煩。
生成設定檔範本
trip --print-config-template > trippy.toml
使用設定檔
trip example.com --config-file /path/to/trippy.toml
設定檔範例片段:
[strategy]
protocol = "icmp"
addr-family = "ipv4"
min-round-duration = "1sec"
max-round-duration = "1sec"
[dns]
dns-resolve-method = "google"
dns-lookup-as-info = true
[report]
report-cycles = 10
[tui]
tui-max-samples = 256
tui-geoip-mode = "short"
客製化 TUI
自訂欄位顯示
# 顯示 hop、loss、sent、received、avg、best、worst、stddev、ttl
trip example.com --tui-custom-columns holsravbwdt
自訂色彩主題
trip example.com --tui-theme-colors bg-color=blue,text-color=ffff00
查看所有可自訂的顏色項目:
trip --print-tui-theme-items
自訂鍵盤綁定
trip example.com --tui-key-bindings previous-hop=k,next-hop=j,quit=shift-q
查看所有可自訂的鍵盤命令:
trip --print-tui-binding-commands
隱私模式(隱藏前幾個 hop)
適合截圖分享時隱藏本地網路資訊:
# 隱藏前 2 個 hop 的 IP 與主機名稱
trip example.com --tui-privacy-max-ttl 2
實際使用場景
場景一:診斷網站連線緩慢
# 使用 TCP 443 追蹤,模擬真實 HTTPS 流量路徑
sudo trip slow-website.com -p tcp -P 443 -r google -z
透過 ASN 資訊可以快速判斷封包在哪個 ISP 或 CDN 節點開始出現高延遲。
場景二:ECMP 負載平衡分析
在有多條等價路徑的網路中(如資料中心),standard traceroute 可能每次走不同路徑:
# 使用 paris 策略確保每次走同一條路徑
sudo trip target-server.com -p udp -R paris
場景三:自動化網路監控
# 每小時收集一次 JSON 報告並存檔
trip example.com -m json -C 10 > /logs/trace-$(date +%Y%m%d%H%M).json
場景四:Docker 環境中使用
docker run -it --rm --cap-add=NET_RAW fujiapple/trippy trip example.com
Trippy vs 傳統工具比較
| 功能 | ping | traceroute | mtr | Trippy |
|---|---|---|---|---|
| 即時統計 | ✗ | ✗ | ✓ | ✓ |
| TUI 介面 | ✗ | ✗ | ✓ | ✓(更現代) |
| TCP/UDP 追蹤 | ✗ | 部分 | 部分 | ✓ |
| ECMP 策略 | ✗ | ✗ | ✗ | ✓ |
| GeoIP 地圖 | ✗ | ✗ | ✗ | ✓ |
| ASN 查詢 | ✗ | ✗ | ✓ | ✓ |
| 多目標同時追蹤 | ✗ | ✗ | ✗ | ✓ |
| 報表輸出 | ✗ | ✗ | ✗ | ✓(JSON/CSV/DOT) |
| 跨平台 | ✓ | ✓ | ✓ | ✓ |
小結
Trippy 是一款功能全面、介面現代的網路診斷工具,特別適合網路工程師、系統管理員和 DevOps 人員日常使用。相較於傳統的 mtr,它在 ECMP 路由分析、報表輸出、GeoIP 整合、多目標追蹤等方面有顯著的改進。
- 官方網站:https://trippy.rs
- GitHub:https://github.com/fujiapple852/trippy
- 最新版本:v0.13.0(2025 年 5 月)