(1)下载tcpdump源码:https://www.tcpdump.org/index.html#latest-releases
(2)下载两个文件(tcpdump与libpcap):tcpdump-4.99.1.tar.gz和libpcap-1.10.1.tar.gz
在libpcap-1.10.1文件夹中执行以下命令
(1)./configure
(如果出现"configure: error: Neither flex nor lex was found."错误,则安装对应组件即可ubuntu下执行
"apt-get install flex bison"缺省安装即可,安装完再执行步骤(1))
(2)make
(3)make install
在tcpdump-4.99.1文件夹中执行以下命令
(1)./configure
(2)make
Demo1:
root@root:/home/root123/code/tcpdump-4.99.1# ./tcpdump tcpdump: verbose output suppressed, use -v[v]... for full protocol decode listening on enp0s3, link-type EN10MB (Ethernet), snapshot length 262144 bytes 15:04:23.698809 IP6 root.mdns > ff02::fb.mdns: 0 [2q] PTR (QM)? _ipps._tcp.local. PTR (QM)? _ipp._tcp.local. (45) 15:04:23.698839 IP root.mdns > 224.0.0.251.mdns: 0 [2q] PTR (QM)? _ipps._tcp.local. PTR (QM)? _ipp._tcp.local. (45) 15:04:23.793857 IP root.40935 > ad.goodwe.com.cn.domain: 4294+ [1au] PTR? b.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.f.f.ip6.arpa. (101) 15:04:24.009623 IP ad.goodwe.com.cn.domain > root.40935: 4294 NXDomain 0/1/1 (165) 15:04:24.009773 IP root.40935 > ad.goodwe.com.cn.domain: 4294+ PTR? b.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.f.f.ip6.arpa. (90) 15:04:24.014792 IP ad.goodwe.com.cn.domain > root.40935: 4294 NXDomain 0/1/0 (154) 15:04:24.015339 IP root.57005 > ad.goodwe.com.cn.domain: 36592+ [1au] PTR? 5.2.4.6.0.1.a.c.2.9.e.9.c.9.a.f.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa. (101)
Demo2:(以虚拟机网卡enp0s3为例)
生成抓包文件test.pcap
root@root:/home/root123/code/tcpdump-4.99.1# ./tcpdump -i enp0s3 -w test.pcap tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), snapshot length 262144 bytes ^C2 packets captured 4 packets received by filter 0 packets dropped by kernel