Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux tcpdump 進階用法:選項詳解、過濾語法、抓包存檔、Wireshark 離線分析工作流

編輯:Linux 教學

tcpdump 完整選項表

選項功能
-a網路/廣播位址解析為名稱
-d/-dd/-ddd輸出 BPF 指令碼 (人類可讀/C/十進位)
-e顯示資料鏈路層頭部
-f外部 IP 以數字顯示
-l行緩衝輸出(適合管道)
-n不做 DNS 反解(快)
-t不印時間戳
-v/-vv詳細/更詳細輸出
-c N抓 N 個封包後退出
-F file從檔案讀取過濾表達式
-i iface指定網卡
-r file讀取 pcap 檔案離線分析
-w file寫入 pcap 檔案
-s snaplen擷取長度(0=完整封包)
-T type強制解析為類型 (rpc/snmp 等)

實戰範例庫

# 1. 抓 eth0 完整封包存檔
tcpdump -i eth0 -w /tmp/eth0.pcap -s 0

# 2. 抓特定主機雙向
tcpdump -i eth0 host 192.168.1.20 -w host.pcap

# 3. 抓該主機 ICMP
tcpdump -i eth0 host 192.168.1.20 and icmp

# 4. 排除常見干擾埠
tcpdump -i eth0 host 192.168.1.20 and not port 10000 and not port 10001 and not port 10002

# 5. 抓 VLAN 1 內 HTTP
tcpdump -i eth0 vlan 1 and port 80

# 6. 抓 PPPoE 撥號
tcpdump -i eth0 pppoes

# 7. 限制 10000 包自動退出
tcpdump -i eth0 -c 10000 -w /tmp/limit.pcap

# 8. 後台長期抓 80 埠
nohup tcpdump -i eth0 port 80 -w /tmp/http.pcap -s 0 &

# 9. 僅看發往 80 埠 (dst port)
tcpdump -i eth0 host 1.2.3.4 and dst port 80

# 10. 僅看來自 80 埠回應 (src port)
tcpdump -i eth0 host 1.2.3.4 and src port 80

關鍵提醒

  • 必須加 -s 0 擷取完整封包,否則預設截斷導致應用層荷載缺失。
  • 生產環境優先 -w file.pcap 離線分析,避免終端輸出阻塞與資訊遺漏。
  • 過濾條件越精確越好,防止磁碟寫滿。
  • Wireshark 開啟 .pcap 享受流圖、重組、專家資訊、圖表分析等高級功能。
Copyright © Windows教程網 All Rights Reserved