下面的例子全是以抓取eth0接口為例,如果不加”-i eth0”是表示抓取所有的接口包括lo冕屯。
如果是無線網(wǎng)卡蟹但,需要將eth0改成wlan0躯泰。
1、抓取包含10.10.10.122的數(shù)據(jù)包
# tcpdump -i eth0 -vnn host 10.10.10.122
2华糖、抓取包含10.10.10.0/24網(wǎng)段的數(shù)據(jù)包
# tcpdump -i eth0 -vnn net 10.10.10.0/24
3麦向、抓取包含端口22的數(shù)據(jù)包
# tcpdump -i eth0 -vnn port 22
4、抓取udp協(xié)議的數(shù)據(jù)包
# tcpdump -i eth0 -vnn? udp
5客叉、抓取icmp協(xié)議的數(shù)據(jù)包
# tcpdump -i eth0 -vnn icmp
6诵竭、抓取arp協(xié)議的數(shù)據(jù)包
# tcpdump -i eth0 -vnn arp
7、抓取ip協(xié)議的數(shù)據(jù)包
# tcpdump -i eth0 -vnn ip
8兼搏、抓取源ip是10.10.10.122數(shù)據(jù)包卵慰。
# tcpdump -i eth0 -vnn src host 10.10.10.122
9佛呻、抓取目的ip是10.10.10.122數(shù)據(jù)包
# tcpdump -i eth0 -vnn dst host 10.10.10.122
10、抓取源端口是22的數(shù)據(jù)包
# tcpdump -i eth0 -vnn src port 22
11吓著、抓取源ip是10.10.10.253且目的ip是22的數(shù)據(jù)包
# tcpdump -i eth0 -vnn src host 10.10.10.253 and dst port 22
12、抓取源ip是10.10.10.122或者包含端口是22的數(shù)據(jù)包
# tcpdump -i eth0 -vnn src host 10.10.10.122 or port 22
13绑莺、抓取源ip是10.10.10.122且端口不是22的數(shù)據(jù)包
[root@ ftp]# tcpdump -i eth0 -vnn src host 10.10.10.122 and not port 22
14暖眼、抓取源ip是10.10.10.2且目的端口是22,或源ip是10.10.10.65且目的端口是80的數(shù)據(jù)包纺裁。
# tcpdump -i eth0 -vnn \( src host 10.10.10.2 and dst port 22 \) or? \( src host 10.10.10.65 and dst port 80 \)
15、抓取源ip是10.10.10.59且目的端口是22,或源ip是10.10.10.68且目的端口是80的數(shù)據(jù)包惭缰。
[root@localhost ~]# tcpdump -i? eth0 -vnn 'src host 10.10.10.59 and dst port 22' or? ' src host 10.10.10.68 and dst port 80 '
16、把抓取的數(shù)據(jù)包記錄存到/tmp/fill文件中笼才,當(dāng)抓取100個數(shù)據(jù)包后就退出程序漱受。
# tcpdump –i eth0 -vnn -w? /tmp/fil1 -c 100
17、從/tmp/fill記錄中讀取tcp協(xié)議的數(shù)據(jù)包
# tcpdump –i eth0 -vnn -r? /tmp/fil1 tcp
18骡送、從/tmp/fill記錄中讀取包含10.10.10.58的數(shù)據(jù)包
# tcpdump –i eth0 -vnn -r? /tmp/fil1 host? 10.10.10.58