Linux 系统中有多种强大的网络抓包和分析工具,以下是常用工具的分类介绍及使用场景:
tcpdump
bash
tcpdump -i eth0 -w capture.pcap # 抓取 eth0 接口流量并保存
tcpdump host 192.168.1.1 and port 80 # 过滤特定主机和端口
tcpdump -nn -v -X 'tcp port 443' # 详细输出 HTTPS 流量tshark(Wireshark 命令行版)
bash
tshark -i eth0 -f "tcp port 22" -w ssh.pcap # 抓取 SSH 流量
tshark -r capture.pcap -Y "http.request" # 读取文件并过滤 HTTP 请求Wireshark
ip.src==192.168.1.1 && httpbash
sudo apt install wireshark # Debian/Ubuntu
sudo yum install wireshark # RHEL/CentOSEttercap
bash
ettercap -T -i eth0 -M arp // // # ARP 欺骗检测模式ngrep
grep,但针对网络流量,支持正则表达式匹配。bash
ngrep -q 'password' port 21 # 捕获 FTP 中的密码字段tcpflow
bash
tcpflow -i eth0 port 80 -c # 捕获并显示 HTTP 流量NetHogs
bash
sudo apt install nethogs # Debian/Ubuntu
nethogs eth0 # 实时监控iftop
bash
iftop -i eth0 -n # 显示 IP 而非域名dnsmasq/dnstop
bash
dnstop -l eth0 # 监控 DNS 查询ssldump
bash
ssldump -i eth0 -k private.key port 443Driftnet
bash
driftnet -i eth0 -d ./captured_imagesiftop + nloadss -tulnp + netstattcpdump → 导出为 pcap → Wireshark 分析sudo/cap_net_raw 能力)。tcpdump -i eth0 'not arp and not port 22'tcpdump 'tcp[tcpflags] & tcp-syn != 0'-C 参数)。根据需求选择工具:
- 快速排查 → tcpdump
- 协议分析 → Wireshark
- 实时监控 → iftop/nethogs
- 安全审计 → ettercap/ssldump