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

tcpdump 抓包實戰速查:從基礎語法到高頻過濾表達式與 Wireshark 聯動分析

編輯:Linux 教學

核心參數速記

參數作用
-i eth1指定網卡
-n不解析域名,顯示 IP/端口號
-v/-vv詳細/更詳細輸出
-c 100抓 100 個包後退出
-s 0抓完整包(默認 96B 截斷)
-w file.cap寫文件不顯示,供 Wireshark 分析
-r file.cap讀文件離線分析
-C 100m分卷寫入,單文件 100MB
-e顯示鏈路層頭部

高頻過濾表達式(BPF 語法)

# 主機
tcpdump -i eth1 host 192.168.1.123

# 端口
tcpdump -i eth1 port 80

# 主機+端口
tcpdump -i eth1 host 192.168.1.123 and port 80

# 排除端口
tcpdump -i eth1 host 192.168.1.123 and not port 22

# 協議
tcpdump -i eth1 icmp
tcpdump -i eth1 tcp
tcpdump -i eth1 udp

# VLAN
tcpdump -i eth1 vlan 1 and port 80

# PPPoE 密碼抓取
tcpdump -i eth1 pppoes

後台長期抓包

nohup tcpdump -i eth1 port 110 -w /tmp/mail.cap -C 100m -c 10000 &

Wireshark 聯動

  • .cap/.pcap 文件雙擊即可用 Wireshark 打開
  • Wireshark 顯示過濾器語法與 tcpdump 略異(如 ip.addr==1.2.3.4),但捕獲文件完全兼容

實戰技巧

  • 抓包前先 tcpdump -i eth1 -c 5 確認流量存在
  • 生產環境務必加 -s 0 -n 避免截斷與 DNS 解析阻塞
  • 大流量場景配合 -C 分卷防止磁盤寫滿
Copyright © Windows教程網 All Rights Reserved