你提到的 “Debian sniffer” 通常指 在 Debian 系统上用于网络抓包/嗅探的工具(如 tcpdump、tshark、Wireshark、或其底层 libpcap / AF_PACKET 机制)。下面从 性能、准确性、资源占用、安全性 四个方面讲如何“优化”。
Debian 默认使用 AF_PACKET:
SOCK_RAWPACKET_MMAP / TPACKET_V3✅ 使用 tcpdump 时:
tcpdump -i eth0 -B 4096
-B:增大内核缓冲区(单位 KB)✅ 使用 tshark:
tshark -i eth0 -B 1024
不要在抓全量包后再过滤。
❌ 错误方式:
tcpdump -i eth0 > all.pcap
✅ 正确方式:
tcpdump -i eth0 'tcp port 443'
常见优化过滤器:
host 192.168.1.10
net 10.0.0.0/8
tcp and not port 22
查看中断:
cat /proc/interrupts | grep eth0
绑定 IRQ 到 CPU:
echo 2 > /proc/irq/XX/smp_affinity
或使用 irqbalance(推荐):
apt install irqbalance
systemctl enable irqbalance
✅ 使用内存缓冲:
tcpdump -i eth0 -w - | buffer > capture.pcap
或限制文件大小:
tcpdump -i eth0 -C 100 -W 10 -w cap.pcap
dumpcap(Wireshark 底层,轻量)netsniff-ng(零拷贝,极快)eBPF + xdp(高级)示例(netsniff-ng):
apt install netsniff-ng
netsniff-ng --in eth0 --out cap.pcap
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.netdev_max_backlog=5000
持久化:
/etc/sysctl.conf
创建抓包用户:
groupadd pcap
chgrp pcap /usr/sbin/tcpdump
chmod 750 /usr/sbin/tcpdump
setcap cap_net_raw,cap_net_admin=eip /usr/sbin/tcpdump
tcpdump -i eth0 -w cap.pcap
# 结束后看统计
或:
cat /proc/net/dev
✅ 用 BPF 过滤
✅ 增大 buffer
✅ 绑定 CPU 中断
✅ 避免写磁盘瓶颈
✅ 使用 netsniff-ng / dumpcap
✅ 非 root 运行
如果你能说明:
我可以给你 更精确的配置示例。