在 CentOS 上,“Sniffer”通常指使用 tcpdump / wireshark / tshark 等抓包工具。下面以 tcpdump(最常用) 为主,介绍如何保存抓包数据。
tcpdump -i eth0 -w capture.pcap
-i eth0:指定网卡(可用 ip addr 查看)-w capture.pcap:保存为 pcap 文件✅ 文件可直接用 Wireshark 打开
tcpdump -i eth0 -c 100 -w capture.pcap
只抓 100 个包
tcpdump -i eth0 port 80 -w http.pcap
tcpdump -i eth0 host 192.168.1.10 -w host.pcap
tcpdump -i eth0 host 192.168.1.10 and port 443 -w https.pcap
tcpdump -i eth0 -w capture.pcap -n -q
nohup tcpdump -i eth0 -w capture.pcap > tcpdump.log 2>&1 &
查看进程:
ps -ef | grep tcpdump
停止抓包:
kill <PID>
timeout 3600 tcpdump -i eth0 -w capture.pcap
yum install -y wireshark-cli
tshark -i eth0 -w capture.pcap
tcpdump -r capture.pcap
scp capture.pcap user@pc:/data/
sudo tcpdump -i eth0 -w capture.pcap
或
yum install -y libpcap
ip addr
或
tcpdump -D
tcpdump -i eth0 -w capture.pcap
如果你告诉我:
我可以帮你写一条精准的抓包命令 ✅