在 Debian 上使用 dumpcap(Wireshark 的命令行抓包工具)时,过滤主要分为 抓包过滤(capture filter) 和 显示过滤(display filter) 两类。dumpcap 本身只支持 抓包过滤(BPF 语法),不支持 Wireshark 的显示过滤语法。
sudo dumpcap -i eth0 -f "过滤表达式" -w output.pcap
示例:
sudo dumpcap -i eth0 -f "tcp port 80" -w http.pcap
tcp
udp
icmp
arp
host 192.168.1.10
src host 192.168.1.10
dst host 192.168.1.10
port 22
tcp port 443
udp port 53
src port 12345
net 192.168.1.0/24
tcp and host 192.168.1.10 and port 80
not arp
tcp or udp
ether host 00:11:22:33:44:55
❌ 下面这种 Wireshark 显示过滤语法 在 dumpcap 中不可用:
http.request.method == "GET"
ip.addr == 192.168.1.1
如果你需要显示过滤,应该:
sudo dumpcap -i eth0 -w capture.pcap
tshark -r capture.pcap -Y "http.request.method == GET"
sudo apt update
sudo apt install wireshark-common
给权限(可选):
sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap
-f 参数只接受 一个字符串如果你有具体场景(比如“只抓某个 IP 的 HTTPS 流量”或“排除广播包”),可以直接告诉我,我帮你写精确过滤规则。