在 CentOS 上进行网络分析的高效做法
一 工具选型与安装
sudo yum install -y tcpdumpsudo yum install -y wireshark wireshark-clisudo yum install -y ngrep二 快速上手 tcpdump
sudo tcpdump -D(常见如 eth0、ens33、lo、any;“any”可监听所有接口)。sudo tcpdump -i eth0(实时输出到终端)。sudo tcpdump -i eth0 -c 100。sudo tcpdump -i eth0 -w capture.pcap。sudo tcpdump -r capture.pcap -nn -vv。-nn(不解析主机名/端口名)、-vv(更详细)、-l(行缓冲,便于管道处理)。以上命令覆盖日常排障的高频用法。三 精准过滤与高效分析
host 192.168.1.10port 80 或 port 443icmp、tcp、udptcp port 80 and host 192.168.1.10src host 192.168.1.10、dst port 22sudo tcpdump -i eth0 'tcp port 80 and host 192.168.1.10' -nn -vvsudo tcpdump -i eth0 icmpwireshark capture.pcapsudo tshark -i eth0 -w http_only.pcap 'tcp port 80'四 进阶与自动化
sudo dumpcap -i any -G 10 -W 10 -w cap_%Y%m%d_%H%M%S.pcapsudo dumpcap -i any -c 1000 -w cap_1k.pcapsudo dumpcap -i any 'tcp port 80' -w http.pcapsudo tshark -r http_only.pcap -T fields -e ip.src -e ip.dst -e tcp.port -e http.hostsudo ngrep -d eth0 'GET /' -W byline五 合规与排错要点
tcpdump -D 确认。-c、-G/-W)控制规模。