1、关键字解释
(1)类型的关键字
host:指定主机,如:host 1.1.1.1
net:指定网络,如:net 1.1.1.0
port:指定端口,如:port 443
(2)确定方向的关键字
src:源地址,如:src 1.1.1.1
dst:目标地址,如:dst 2.2.2.2
(3)协议的关键字(默认所有协议)
tcp、udp、fddi、ip、arp、rarp
(4)其它关键字
gateway、broadcast、less、greater
(5)常用表达式
与:&&、and
或: ||、or
非:!、not
(6)其他参数详解
i:监听主机的该网卡上的数据流,如果没有指定,就会使用最小网卡编号的网卡(不包括环路),linux 2.2 内核及之后的版本支持 any 网卡,用于指代任意网卡
n:显示ip,而不是主机名
nn:显示port,而不是服务名
c:抓取指定数目的包
l:如果没有使用 -w 选项,就可以将报文打印到标准输出(默认)
w:直接将包写入文件中,并不分析和打印出来
2、常用命令
(1)获取两个ip之间的包
tcpdump host 1.1.1.1 and 2.2.2.2 -i eth0 -n -nn -c 10
(2)获取1.1.1.1访问本机443端口的包
tcpdump src host 1.1.1.1 and dst port 443 -i eth0 -n -nn -c 10
(3)获取访问本机443端口的tcp包
tcpdump dst host 1.1.1.1 and tcp dst port 443 -i eth0 -n -nn -c 10
(4)获取1.1.1.1和除2.2.2.2之外所有主机的包
tcpdump host 1.1.1.1 and not 2.2.2.2 -i eth0 -n -nn -c 10