温馨提示×

debian dumpcap如何过滤

小樊
41
2026-09-03 15:21:10
栏目: 智能运维

在 Debian 上使用 dumpcap(Wireshark 的命令行抓包工具)时,过滤主要分为 抓包过滤(capture filter)显示过滤(display filter) 两类。dumpcap 本身只支持 抓包过滤(BPF 语法),不支持 Wireshark 的显示过滤语法。


一、dumpcap 抓包过滤(capture filter)

1️⃣ 基本用法

sudo dumpcap -i eth0 -f "过滤表达式" -w output.pcap

示例:

sudo dumpcap -i eth0 -f "tcp port 80" -w http.pcap

2️⃣ 常用抓包过滤示例

✅ 按协议

tcp
udp
icmp
arp

✅ 按 IP 地址

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

✅ 按 MAC 地址

ether host 00:11:22:33:44:55

二、dumpcap 不支持显示过滤

❌ 下面这种 Wireshark 显示过滤语法 在 dumpcap 中不可用:

http.request.method == "GET"
ip.addr == 192.168.1.1

如果你需要显示过滤,应该:

  • 用 dumpcap 抓包
  • tsharkWireshark 分析

三、配合 tshark 做显示过滤(推荐)

抓包

sudo dumpcap -i eth0 -w capture.pcap

用 tshark 过滤

tshark -r capture.pcap -Y "http.request.method == GET"

四、Debian 安装 dumpcap

sudo apt update
sudo apt install wireshark-common

给权限(可选):

sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap

五、常见坑

  1. 必须用 sudo(抓包需要 raw 权限)
  2. 过滤语法必须是 BPF
  3. -f 参数只接受 一个字符串

如果你有具体场景(比如“只抓某个 IP 的 HTTPS 流量”或“排除广播包”),可以直接告诉我,我帮你写精确过滤规则。

0