命令格式
tcpdump [option] [expression]
重要选项
-i : 指定读取 packets 的网卡,如果不指定,以读取序号最小的网卡,如系统存在 eth0 和 eth1, 则读取 eth0 的。
Note: 如果是本机与本机之间通信,请使用 -i lo, 即使绑定的地址不是 loopback 地址。
-w , -r : 将 packets 写入文件和从文件读入 packets, 这个用于事后分析而不是现场分析。
-c : 处理 count 个 packet 之后推出。如果不指定 count, 命令会一直处理,知道收到相关信号。
-n: Don’t convert host addresses to names. This can be used to avoid DNS lookups.
-nn: Don’t convert protocol and port numbers etc. to names either.
表达式
tcpdump -ieth0 -v dst port 22 and \(src host 10.144.66.170 or src host 119.28.50.178\)
Note:
1. 表达式可以用双引号、单引号包含,也可以不用引号
2. ()
需要转义
案例
- 查看某服务进程是否收到包,绑定地址:udp://172.25.40.208:6668
tcpdump -ilo udp dst port 6668
tcpdump -ieth1 udp dst port 6668
Note: udp dst port 6668 == (udp) and (dst port 6668)