tcpdump抓包核心三步:选网卡(-i)、加过滤(host/port/protocol等)、控输出(-c/-w/-r/-s 0/-v);系统自带,无需安装,适合快速排查网络连通性、端口访问及协议异常。

直接上手用 tcpdump 抓包,核心就三步:选网卡、加过滤、控制输出。不装额外软件,系统自带就能跑,适合快速排查网络连通性、端口访问、协议异常等问题。
先确认可用网卡,避免抓错接口:
tcpdump -D 或 tcpdump --list-interfaces —— 列出所有可抓包的网卡(如 eth0、ens33、lo)tcpdump -i eth0 —— 监听 eth0 上所有流量(默认只抓前 68 字节,且会反解 IP 和端口名)tcpdump -i any —— 抓所有网卡(含 lo),适合不确定流量走哪条路径时加过滤能大幅减少干扰,-nn 是高频组合(禁 DNS 反解 + 禁端口名映射),建议默认带上:
tcpdump -i eth0 -nn host 192.168.1.100
tcpdump -i eth0 -nn dst host 192.168.1.100
tcpdump -i eth0 -nn src host 192.168.1.100
tcpdump -i eth0 -nn port 80
tcpdump -i eth0 -nn icmp 或 tcpdump -i eth0 -nn tcp
tcpdump -i eth0 -nn dst host 192.168.1.100 and dst port 22
让输出更可控、结果更可靠:
-c 10 —— 只抓 10 个包后自动退出,防刷屏;例:tcpdump -i eth0 -nn -c 10 icmp
-w file.pcap —— 保存为 pcap 文件,供 Wireshark 深度分析;例:tcpdump -i eth0 -nn -w debug.pcap port 443
-r file.pcap —— 读取已保存的抓包文件:tcpdump -r debug.pcap -nn
-s 0 —— 抓完整包(不截断),尤其查 HTTP 内容或 TLS 握手时必需;tcpdump -i eth0 -nn -s 0 port 80
-v 或 -vv —— 显示更多协议细节(TTL、TCP 标志位、窗口大小等)比如怀疑某服务没响应,想看是否真有请求到达:
tcpdump -i eth0 -nn -s 0 -c 20 'dst host 10.0.5.20 and dst port 8080'
这条命令表示:在 eth0 上抓 20 个发往 10.0.5.20:8080 的完整包,不反解、不截断,抓完即停。
基本上就这些。用熟几个组合,比开 GUI 工具还快。
以上就是Linux 怎么用 tcpdump 抓包?最常用命令的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号