tcpdump

原文地址: http://www.wains.be/pub/networking/tcpdump_advanced_filters.txt

基本语法:
过滤主机:
源/目的IP含有192.168.1.1
# tcpdump -i eth1 host 192.168.1.1

# tcpdump -i eth1 src host 192.168.1.1
目的
# tcpdump -i eth1 dst host 192.168.1.1

过滤端口:
源/目的端口为25
# tcpdump -i eth1 port 25

# tcpdump -i eth1 src port 25
目的:
# tcpdump -i eth1 dst port 25

过滤网络:
# tcpdump -i eth1 net 192.168
# tcpdump -i eth1 src net 192.168
# tcpdump -i eth1 dst net 192.168

过滤协议:
# tcpdump -i eth1 arp
# tcpdump -i eth1 ip

# tcpdump -i eth1 tcp
# tcpdump -i eth1 udp
# tcpdump -i eth1 icmp

结合起来使用:
否定    : ! or "not" (没有引号)
连接 : && or "and"
二选一   : || or "or"

- 匹配目的地址为 192.168.1.254或192.168.1.200以及80端口
# tcpdump -i eth1 '((tcp) and (port 80) and ((dst host 192.168.1.254) or (dst host 192.168.1.200)))'

- ICMP协议,目的mac地址为00:01:02:03:04:05
# tcpdump -i eth1 '((icmp) and ((ether dst host 00:01:02:03:04:05)))'

- 匹配除了192.168.1.200外的192.168网段
# tcpdump -i eth1 '((tcp) and ((dst net 192.168) and (not dst host 192.168.1.200)))'

你可能感兴趣的:(tcpdump)