TCPdump: dump  traffic on a network ,根据使用者的定义对网络上的数据包进行截获的一种包分析工具。 TCPdump 可以讲网络中传送的数据包的 头信息完全截获下来提供分析, 它支持针对网络层,协议,主机,网络或端口的过滤, 并提供and,or ,not 等逻辑语句来帮助去掉无用的信息。

Tcpdump  prints  out  the headers of packets on a network interface that match the boolean expression.  It can also be run with the  -w flag,  which  causes it to save the packet data to a file for later analysis, and/or with the -r flag, which causes it to read  from  a saved packet file rather than to read packets from a network inter-face.  In all cases, only packets that  match  expression will  be processed by tcpdump.

选项:

-i : 指定监听的网络接口, 不加-i 选项表示抓取所有的接口包括lo 

-v: 输出详细信息

-nn: 显示格式为IP+Port ,默认为主机名+服务名

-c: 抓取包的数量, 到达该数量后则停止抓取

-T:将监听到的包直接解释为指定类型的报文, rpc(远程过程调用)  snmp (简单网络管理协议)

实例:

//打印所有进入或离开sundown 的数据包

tcpdump host sundown

//指定ip ,拦截所有指定ip的主机收到和发出的所有的数据包

tcpdump host 210.27.48.1

//打印helios 与hot 或者ace 之间通信的数据包

tcpdump host helios and \(hot or ace\)

 //截获主机hostname 发送的所有数据

tcpdump -i eth0 src host hostname

//件事所有送到主机hostname 的数据包

tcpdump -i eth0 dst host hostname

//对本机的udp 123 端口进行监视

tcpdump udp port 123

//打印所有通过网关snup 的ftp 数据包, ‘’防止shell 对括号进行错误解析

tcpdump 'gateway snup and (port ftp or ftp-data)'

//打印所有原地址或目标地址是本地主机的ip 数据包

tcpdump ip and not net localnet   如果本地网络通过网关连到另一网络, 则另一网络并不能算做本地网络