Debian 系统下“sniffer”通常指网络嗅探工具(如 Wireshark、tcpdump、ngrep 等),用于抓取和分析网络数据包。下面给你常用工具的入门教程 + 实操示例,适合 Debian 10/11/12。
| 工具 | 用途 | 推荐场景 |
|---|---|---|
| tcpdump | 命令行抓包 | 服务器、无 GUI |
| Wireshark | 图形化抓包 | 桌面分析 |
| tshark | Wireshark 命令行版 | 自动化 |
| ngrep | 内容匹配抓包 | HTTP / DNS 分析 |
| ss / netstat | 连接查看 | 辅助排查 |
sudo apt update
sudo apt install tcpdump
查看网卡:
ip addr
抓所有流量:
sudo tcpdump -i eth0
抓 HTTP(80 端口):
sudo tcpdump -i eth0 port 80
抓 HTTPS(443):
sudo tcpdump -i eth0 port 443
只抓 100 个包:
sudo tcpdump -c 100 -i eth0
保存为 pcap 文件:
sudo tcpdump -i eth0 -w capture.pcap
读取 pcap 文件:
tcpdump -r capture.pcap
sudo apt install wireshark
运行:
sudo wireshark
⚠️ 建议配置非 root 抓包(更安全)
sudo dpkg-reconfigure wireshark-common
选择 ✅ “Yes”,然后把用户加入组:
sudo usermod -aG wireshark $USER
注销或重启后生效。
sudo apt install tshark
示例:
tshark -i eth0
tshark -i eth0 -Y "http"
tshark -r capture.pcap
sudo apt install ngrep
抓 HTTP 请求:
sudo ngrep -d eth0 port 80
抓包含 password 的流量:
sudo ngrep -d eth0 password
Debian 默认 普通用户不能抓包,必须:
✅ 使用 sudo
✅ 或加入 wireshark / netdev 组
sudo usermod -aG netdev $USER
网络嗅探只能用于:
❌ 未经授权抓他人流量可能违法(包括公司内网)
你可以直接说:
我可以给你更精确的命令和过滤规则。