欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

在Linux中使用tcpdump命令捕获与分析数据包详解

程序员文章站 2023-11-14 22:33:52
前言 tcpdump 是一个有名的命令行数据包分析工具。我们可以使用 tcpdump 命令捕获实时 tcp/ip 数据包,这些数据包也可以保存到文件中。之后这些捕获的数据...

前言

tcpdump 是一个有名的命令行数据包分析工具。我们可以使用 tcpdump 命令捕获实时 tcp/ip 数据包,这些数据包也可以保存到文件中。之后这些捕获的数据包可以通过 tcpdump 命令进行分析。tcpdump 命令在网络层面进行故障排除时变得非常方便。

tcpdump 在大多数 linux 发行版中都能用,对于基于 debian 的linux,可以使用 apt 命令安装它。

# apt install tcpdump -y

在基于 rpm 的 linux 操作系统上,可以使用下面的 yum 命令安装 tcpdump。

# yum install tcpdump -y

当我们在没用任何选项的情况下运行 tcpdump 命令时,它将捕获所有接口的数据包。因此,要停止或取消 tcpdump 命令,请键入 ctrl+c。在本教程中,我们将使用不同的实例来讨论如何捕获和分析数据包。

示例:1)从特定接口捕获数据包

当我们在没用任何选项的情况下运行 tcpdump 命令时,它将捕获所有接口上的数据包,因此,要从特定接口捕获数据包,请使用选项 -i,后跟接口名称。

语法:

# tcpdump -i {接口名}

假设我想从接口 enp0s3 捕获数据包。

输出将如下所示,

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type en10mb (ethernet), capture size 262144 bytes
06:43:22.905890 ip compute-0-1.example.com.ssh > 169.144.0.1.39374: flags [p.], seq 21952160:21952540, ack 13537, win 291, options [nop,nop,ts val 26164373 ecr 6580205], length 380
06:43:22.906045 ip compute-0-1.example.com.ssh > 169.144.0.1.39374: flags [p.], seq 21952540:21952760, ack 13537, win 291, options [nop,nop,ts val 26164373 ecr 6580205], length 220
06:43:22.906150 ip compute-0-1.example.com.ssh > 169.144.0.1.39374: flags [p.], seq 21952760:21952980, ack 13537, win 291, options [nop,nop,ts val 26164373 ecr 6580205], length 220
06:43:22.906291 ip 169.144.0.1.39374 > compute-0-1.example.com.ssh: flags [.], ack 21952980, win 13094, options [nop,nop,ts val 6580205 ecr 26164373], length 0
06:43:22.906303 ip 169.144.0.1.39374 > compute-0-1.example.com.ssh: flags [p.], seq 13537:13609, ack 21952980, win 13094, options [nop,nop,ts val 6580205 ecr 26164373], length 72
06:43:22.906322 ip compute-0-1.example.com.ssh > 169.144.0.1.39374: flags [p.], seq 21952980:21953200, ack 13537, win 291, options [nop,nop,ts val 26164373 ecr 6580205], length 220
^c
109930 packets captured
110065 packets received by filter
133 packets dropped by kernel
[[email protected] ~]#

示例:2)从特定接口捕获特定数量数据包

假设我们想从特定接口(如 enp0s3)捕获 12 个数据包,这可以使用选项 -c {数量} -i {接口名称} 轻松实现。

root@compute-0-1 ~]# tcpdump -c 12 -i enp0s3

上面的命令将生成如下所示的输出,

在Linux中使用tcpdump命令捕获与分析数据包详解

n-number-packsets-tcpdump-interface

示例:3)显示 tcpdump 的所有可用接口

使用 -d 选项显示 tcpdump 命令的所有可用接口,

[root@compute-0-1 ~]# tcpdump -d
1.enp0s3
2.enp0s8
3.ovs-system
4.br-int
5.br-tun
6.nflog (linux netfilter log (nflog) interface)
7.nfqueue (linux netfilter queue (nfqueue) interface)
8.usbmon1 (usb bus number 1)
9.usbmon2 (usb bus number 2)
10.qbra692e993-28
11.qvoa692e993-28
12.qvba692e993-28
13.tapa692e993-28
14.vxlan_sys_4789
15.any (pseudo-device that captures on all interfaces)
16.lo [loopback]
[[email protected] ~]#

我正在我的一个 openstack 计算节点上运行 tcpdump 命令,这就是为什么在输出中你会看到数字接口、标签接口、网桥和 vxlan 接口。

示例:4)捕获带有可读时间戳的数据包(-tttt 选项)

默认情况下,在 tcpdump 命令输出中,不显示可读性好的时间戳,如果您想将可读性好的时间戳与每个捕获的数据包相关联,那么使用 -tttt 选项,示例如下所示,

[[email protected] ~]# tcpdump -c 8 -tttt -i enp0s3
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type en10mb (ethernet), capture size 262144 bytes
2018-08-25 23:23:36.954883 ip compute-0-1.example.com.ssh > 169.144.0.1.39406: flags [p.], seq 1449206247:1449206435, ack 3062020950, win 291, options [nop,nop,ts val 86178422 ecr 21583714], length 188
2018-08-25 23:23:36.955046 ip 169.144.0.1.39406 > compute-0-1.example.com.ssh: flags [.], ack 188, win 13585, options [nop,nop,ts val 21583717 ecr 86178422], length 0
2018-08-25 23:23:37.140097 ip controller0.example.com.amqp > compute-0-1.example.com.57818: flags [p.], seq 814607956:814607964, ack 2387094506, win 252, options [nop,nop,ts val 86172228 ecr 86176695], length 8
2018-08-25 23:23:37.140175 ip compute-0-1.example.com.57818 > controller0.example.com.amqp: flags [.], ack 8, win 237, options [nop,nop,ts val 86178607 ecr 86172228], length 0
2018-08-25 23:23:37.355238 ip compute-0-1.example.com.57836 > controller0.example.com.amqp: flags [p.], seq 1080415080:1080417400, ack 1690909362, win 237, options [nop,nop,ts val 86178822 ecr 86163054], length 2320
2018-08-25 23:23:37.357119 ip controller0.example.com.amqp > compute-0-1.example.com.57836: flags [.], ack 2320, win 1432, options [nop,nop,ts val 86172448 ecr 86178822], length 0
2018-08-25 23:23:37.357545 ip controller0.example.com.amqp > compute-0-1.example.com.57836: flags [p.], seq 1:22, ack 2320, win 1432, options [nop,nop,ts val 86172449 ecr 86178822], length 21
2018-08-25 23:23:37.357572 ip compute-0-1.example.com.57836 > controller0.example.com.amqp: flags [.], ack 22, win 237, options [nop,nop,ts val 86178825 ecr 86172449], length 0
8 packets captured
134 packets received by filter
69 packets dropped by kernel
[[email protected] ~]#

示例:5)捕获数据包并将其保存到文件(-w 选项)

使用 tcpdump 命令中的 -w 选项将捕获的 tcp/ip 数据包保存到一个文件中,以便我们可以在将来分析这些数据包以供进一步分析。

语法:

# tcpdump -w 文件名.pcap -i {接口名}

注意:文件扩展名必须为 .pcap。

假设我要把 enp0s3 接口捕获到的包保存到文件名为 enp0s3-26082018.pcap。

[root@compute-0-1 ~]# tcpdump -w enp0s3-26082018.pcap -i enp0s3

上述命令将生成如下所示的输出,

[root@compute-0-1 ~]# tcpdump -w enp0s3-26082018.pcap -i enp0s3
tcpdump: listening on enp0s3, link-type en10mb (ethernet), capture size 262144 bytes
^c841 packets captured
845 packets received by filter
0 packets dropped by kernel
[root@compute-0-1 ~]# ls
anaconda-ks.cfg enp0s3-26082018.pcap
[root@compute-0-1 ~]#

捕获并保存大小大于 n 字节的数据包。

[root@compute-0-1 ~]# tcpdump -w enp0s3-26082018-2.pcap greater 1024

捕获并保存大小小于 n 字节的数据包。

[root@compute-0-1 ~]# tcpdump -w enp0s3-26082018-3.pcap less 1024

示例:6)从保存的文件中读取数据包(-r 选项)

在上面的例子中,我们已经将捕获的数据包保存到文件中,我们可以使用选项 -r 从文件中读取这些数据包,例子如下所示,

[root@compute-0-1 ~]# tcpdump -r enp0s3-26082018.pcap

用可读性高的时间戳读取包内容,

[root@compute-0-1 ~]# tcpdump -tttt -r enp0s3-26082018.pcap
reading from file enp0s3-26082018.pcap, link-type en10mb (ethernet)
2018-08-25 22:03:17.249648 ip compute-0-1.example.com.ssh > 169.144.0.1.39406: flags [p.], seq 1426167803:1426167927, ack 3061962134, win 291, options
[nop,nop,ts val 81358717 ecr 20378789], length 124
2018-08-25 22:03:17.249840 ip 169.144.0.1.39406 > compute-0-1.example.com.ssh: flags [.], ack 124, win 564, options [nop,nop,ts val 20378791 ecr 81358
717], length 0
2018-08-25 22:03:17.454559 ip controller0.example.com.amqp > compute-0-1.example.com.57836: flags [.], ack 1079416895, win 1432, options [nop,nop,ts v
al 81352560 ecr 81353913], length 0
2018-08-25 22:03:17.454642 ip compute-0-1.example.com.57836 > controller0.example.com.amqp: flags [.], ack 1, win 237, options [nop,nop,ts val 8135892
2 ecr 81317504], length 0
2018-08-25 22:03:17.646945 ip compute-0-1.example.com.57788 > controller0.example.com.amqp: flags [.], seq 106760587:106762035, ack 688390730, win 237
, options [nop,nop,ts val 81359114 ecr 81350901], length 1448
2018-08-25 22:03:17.647043 ip compute-0-1.example.com.57788 > controller0.example.com.amqp: flags [p.], seq 1448:1956, ack 1, win 237, options [nop,no
p,ts val 81359114 ecr 81350901], length 508
2018-08-25 22:03:17.647502 ip controller0.example.com.amqp > compute-0-1.example.com.57788: flags [.], ack 1956, win 1432, options [nop,nop,ts val 813
52753 ecr 81359114], length 0
.........................................................................................................................

示例:7)仅捕获特定接口上的 ip 地址数据包(-n 选项)

使用 tcpdump 命令中的 -n 选项,我们能只捕获特定接口上的 ip 地址数据包,示例如下所示,

[root@compute-0-1 ~]# tcpdump -n -i enp0s3

上述命令输出如下,

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type en10mb (ethernet), capture size 262144 bytes
22:22:28.537904 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 1433301395:1433301583, ack 3061976250, win 291, options [nop,nop,ts val 82510005 ecr 20666610], length 188
22:22:28.538173 ip 169.144.0.1.39406 > 169.144.0.20.ssh: flags [.], ack 188, win 9086, options [nop,nop,ts val 20666613 ecr 82510005], length 0
22:22:28.538573 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 188:552, ack 1, win 291, options [nop,nop,ts val 82510006 ecr 20666613], length 364
22:22:28.538736 ip 169.144.0.1.39406 > 169.144.0.20.ssh: flags [.], ack 552, win 9086, options [nop,nop,ts val 20666613 ecr 82510006], length 0
22:22:28.538874 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 552:892, ack 1, win 291, options [nop,nop,ts val 82510006 ecr 20666613], length 340
22:22:28.539042 ip 169.144.0.1.39406 > 169.144.0.20.ssh: flags [.], ack 892, win 9086, options [nop,nop,ts val 20666613 ecr 82510006], length 0
22:22:28.539178 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 892:1232, ack 1, win 291, options [nop,nop,ts val 82510006 ecr 20666613], length 340
22:22:28.539282 ip 169.144.0.1.39406 > 169.144.0.20.ssh: flags [.], ack 1232, win 9086, options [nop,nop,ts val 20666614 ecr 82510006], length 0
22:22:28.539479 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 1232:1572, ack 1, win 291, options [nop,nop,ts val 82510006 ecr 20666614], length 340
22:22:28.539595 ip 169.144.0.1.39406 > 169.144.0.20.ssh: flags [.], ack 1572, win 9086, options [nop,nop,ts val 20666614 ecr 82510006], length 0
22:22:28.539760 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 1572:1912, ack 1, win 291, options [nop,nop,ts val 82510007 ecr 20666614], length 340
.........................................................................

您还可以使用 tcpdump 命令中的 -c 和 -n 选项捕获 n 个 ip 地址包,

[root@compute-0-1 ~]# tcpdump -c 25 -n -i enp0s3

示例:8)仅捕获特定接口上的 tcp 数据包

在 tcpdump 命令中,我们能使用 tcp 选项来只捕获 tcp 数据包,

[root@compute-0-1 ~]# tcpdump -i enp0s3 tcp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type en10mb (ethernet), capture size 262144 bytes
22:36:54.521053 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 1433336467:1433336655, ack 3061986618, win 291, options [nop,nop,ts val 83375988 ecr 20883106], length 188
22:36:54.521474 ip 169.144.0.1.39406 > 169.144.0.20.ssh: flags [.], ack 188, win 9086, options [nop,nop,ts val 20883109 ecr 83375988], length 0
22:36:54.522214 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 188:552, ack 1, win 291, options [nop,nop,ts val 83375989 ecr 20883109], length 364
22:36:54.522508 ip 169.144.0.1.39406 > 169.144.0.20.ssh: flags [.], ack 552, win 9086, options [nop,nop,ts val 20883109 ecr 83375989], length 0
22:36:54.522867 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 552:892, ack 1, win 291, options [nop,nop,ts val 83375990 ecr 20883109], length 340
22:36:54.523006 ip 169.144.0.1.39406 > 169.144.0.20.ssh: flags [.], ack 892, win 9086, options [nop,nop,ts val 20883109 ecr 83375990], length 0
22:36:54.523304 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 892:1232, ack 1, win 291, options [nop,nop,ts val 83375990 ecr 20883109], length 340
22:36:54.523461 ip 169.144.0.1.39406 > 169.144.0.20.ssh: flags [.], ack 1232, win 9086, options [nop,nop,ts val 20883110 ecr 83375990], length 0
22:36:54.523604 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 1232:1572, ack 1, win 291, options [nop,nop,ts val 83375991 ecr 20883110], length 340
...................................................................................................................................................

示例:9)从特定接口上的特定端口捕获数据包

使用 tcpdump 命令,我们可以从特定接口 enp0s3 上的特定端口(例如 22)捕获数据包。

语法:

# tcpdump -i {interface-name} port {port_number}
[root@compute-0-1 ~]# tcpdump -i enp0s3 port 22
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type en10mb (ethernet), capture size 262144 bytes
22:54:45.032412 ip compute-0-1.example.com.ssh > 169.144.0.1.39406: flags [p.], seq 1435010787:1435010975, ack 3061993834, win 291, options [nop,nop,ts val 84446499 ecr 21150734], length 188
22:54:45.032631 ip 169.144.0.1.39406 > compute-0-1.example.com.ssh: flags [.], ack 188, win 9131, options [nop,nop,ts val 21150737 ecr 84446499], length 0
22:54:55.037926 ip compute-0-1.example.com.ssh > 169.144.0.1.39406: flags [p.], seq 188:576, ack 1, win 291, options [nop,nop,ts val 84456505 ecr 21150737], length 388
22:54:55.038106 ip 169.144.0.1.39406 > compute-0-1.example.com.ssh: flags [.], ack 576, win 9154, options [nop,nop,ts val 21153238 ecr 84456505], length 0
22:54:55.038286 ip compute-0-1.example.com.ssh > 169.144.0.1.39406: flags [p.], seq 576:940, ack 1, win 291, options [nop,nop,ts val 84456505 ecr 21153238], length 364
22:54:55.038564 ip 169.144.0.1.39406 > compute-0-1.example.com.ssh: flags [.], ack 940, win 9177, options [nop,nop,ts val 21153238 ecr 84456505], length 0
22:54:55.038708 ip compute-0-1.example.com.ssh > 169.144.0.1.39406: flags [p.], seq 940:1304, ack 1, win 291, options [nop,nop,ts val 84456506 ecr 21153238], length 364
............................................................................................................................

示例:10)在特定接口上捕获来自特定来源 ip 的数据包

在 tcpdump 命令中,使用 src 关键字后跟 ip 地址,我们可以捕获来自特定来源 ip 的数据包,

语法:

# tcpdump -n -i {接口名} src {ip 地址}

例子如下,

[root@compute-0-1 ~]# tcpdump -n -i enp0s3 src 169.144.0.10
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type en10mb (ethernet), capture size 262144 bytes
23:03:45.912733 ip 169.144.0.10.amqp > 169.144.0.20.57800: flags [.], ack 526623844, win 243, options [nop,nop,ts val 84981008 ecr 84982372], length 0
23:03:46.136757 ip 169.144.0.10.amqp > 169.144.0.20.57796: flags [.], ack 2535995970, win 252, options [nop,nop,ts val 84981232 ecr 84982596], length 0
23:03:46.153398 ip 169.144.0.10.amqp > 169.144.0.20.57798: flags [.], ack 3623063621, win 243, options [nop,nop,ts val 84981248 ecr 84982612], length 0
23:03:46.361160 ip 169.144.0.10.amqp > 169.144.0.20.57802: flags [.], ack 2140263945, win 252, options [nop,nop,ts val 84981456 ecr 84982821], length 0
23:03:46.376926 ip 169.144.0.10.amqp > 169.144.0.20.57808: flags [.], ack 175946224, win 252, options [nop,nop,ts val 84981472 ecr 84982836], length 0
23:03:46.505242 ip 169.144.0.10.amqp > 169.144.0.20.57810: flags [.], ack 1016089556, win 252, options [nop,nop,ts val 84981600 ecr 84982965], length 0
23:03:46.616994 ip 169.144.0.10.amqp > 169.144.0.20.57812: flags [.], ack 832263835, win 252, options [nop,nop,ts val 84981712 ecr 84983076], length 0
23:03:46.809344 ip 169.144.0.10.amqp > 169.144.0.20.57814: flags [.], ack 2781799939, win 252, options [nop,nop,ts val 84981904 ecr 84983268], length 0
23:03:46.809485 ip 169.144.0.10.amqp > 169.144.0.20.57816: flags [.], ack 1662816815, win 252, options [nop,nop,ts val 84981904 ecr 84983268], length 0
23:03:47.033301 ip 169.144.0.10.amqp > 169.144.0.20.57818: flags [.], ack 2387094362, win 252, options [nop,nop,ts val 84982128 ecr 84983492], length 0
^c
10 packets captured
12 packets received by filter
0 packets dropped by kernel

示例:11)在特定接口上捕获来自特定目的 ip 的数据包

语法:

# tcpdump -n -i {接口名} dst {ip 地址}

[root@compute-0-1 ~]# tcpdump -n -i enp0s3 dst 169.144.0.1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type en10mb (ethernet), capture size 262144 bytes
23:10:43.520967 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 1439564171:1439564359, ack 3062005550, win 291, options [nop,nop,ts val 85404988 ecr 21390356], length 188
23:10:43.521441 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 188:408, ack 1, win 291, options [nop,nop,ts val 85404988 ecr 21390359], length 220
23:10:43.521719 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 408:604, ack 1, win 291, options [nop,nop,ts val 85404989 ecr 21390359], length 196
23:10:43.521993 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 604:800, ack 1, win 291, options [nop,nop,ts val 85404989 ecr 21390359], length 196
23:10:43.522157 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 800:996, ack 1, win 291, options [nop,nop,ts val 85404989 ecr 21390359], length 196
23:10:43.522346 ip 169.144.0.20.ssh > 169.144.0.1.39406: flags [p.], seq 996:1192, ack 1, win 291, options [nop,nop,ts val 85404989 ecr 21390359], length 196
.........................................................................................

示例:12)捕获两台主机之间的 tcp 数据包通信

假设我想捕获两台主机 169.144.0.1 和 169.144.0.20 之间的 tcp 数据包,示例如下所示,

[root@compute-0-1 ~]# tcpdump -w two-host-tcp-comm.pcap -i enp0s3 tcp and \(host 169.144.0.1 or host 169.144.0.20\)

使用 tcpdump 命令只捕获两台主机之间的 ssh 数据包流,

[root@compute-0-1 ~]# tcpdump -w ssh-comm-two-hosts.pcap -i enp0s3 src 169.144.0.1 and port 22 and dst 169.144.0.20 and port 22

示例:13)捕获两台主机之间(来回)的 udp 网络数据包

语法:

# tcpdump -w -s -i udp and \(host and host \)

[root@compute-0-1 ~]# tcpdump -w two-host-comm.pcap -s 1000 -i enp0s3 udp and \(host 169.144.0.10 and host 169.144.0.20\)

示例:14)捕获十六进制和 ascii 格式的数据包

使用 tcpdump 命令,我们可以以 ascii 和十六进制格式捕获 tcp/ip 数据包,

要使用 -a 选项捕获 ascii 格式的数据包,示例如下所示:

[root@compute-0-1 ~]# tcpdump -c 10 -a -i enp0s3
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type en10mb (ethernet), capture size 262144 bytes
00:37:10.520060 ip compute-0-1.example.com.ssh > 169.144.0.1.39406: flags [p.], seq 1452637331:1452637519, ack 3062125586, win 333, options [nop,nop,ts val 90591987 ecr 22687106], length 188
e...[root@compute-0-1 @...............v.|...t....mt......
.fr..z-....b.:..z5...{.'p....]."}...z..9.?......."root@compute-0-1 <.....v..c.....{,...okp.2.*...`..-ss..1s...........:.o[.....{g..%ze.pn.t..n.... ....qb..5...n.....`...:=...[..0....k.....s.:..5!.9..g....!-..'..
00:37:10.520319 ip 169.144.0.1.39406 > compute-0-1.example.com.ssh: flags [.], ack 188, win 13930, options [nop,nop,ts val 22687109 ecr 90591987], length 0
root@compute-0-1 @.|+..............t.v.}o..6j.d.....
.z-..fr.
00:37:11.687543 ip controller0.example.com.amqp > compute-0-1.example.com.57800: flags [.], ack 526624548, win 243, options [nop,nop,ts val 90586768 ecr 90588146], length 0
root@compute-0-1 @.!l...
.....(..g....c.$...........
.f>..fc.
00:37:11.687612 ip compute-0-1.example.com.57800 > controller0.example.com.amqp: flags [.], ack 1, win 237, options [nop,nop,ts val 90593155 ecr 90551716], length 0
root@compute-0-1 @..........
...(.c.$g.......se.....
.fw..e..
..................................................................................................................................................

要同时以十六进制和 ascii 格式捕获数据包,请使用 -xx 选项。

[root@compute-0-1 ~]# tcpdump -c 10 -xx -i enp0s3
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s3, link-type en10mb (ethernet), capture size 262144 bytes
00:39:15.124363 ip compute-0-1.example.com.ssh > 169.144.0.1.39406: flags [p.], seq 1452640859:1452641047, ack 3062126346, win 333, options [nop,nop,ts val 90716591 ecr 22718257], length 188
0x0000: 0a00 2700 0000 0800 27f4 f935 0800 4510 ..'.....'..5..e.
0x0010: 00f0 5bc6 4000 4006 8afc a990 0014 a990 ..[root@compute-0-1 @.........
0x0020: 0001 0016 99ee 5695 8a5b b684 570a 8018 ......v..[..w...
0x0030: 014d 5418 0000 0101 080a 0568 39af 015a .mt........h9..z
0x0040: a731 adb7 58b6 1a0f 2006 df67 c9b6 4479 .1..x......g..dy
0x0050: 19fd 2c3d 2042 3313 35b9 a160 fa87 d42c ..,=.b3.5..`...,
0x0060: 89a9 3d7d dfbf 980d 2596 4f2a 99ba c92a ..=}....%.o*...*
0x0070: 3e1e 7bf7 3af2 a5cc ee4f 10bc 7dfc 630d >.{.:....o..}.c.
0x0080: 898a 0e16 6825 56c7 b683 1de4 3526 ff04 ....h%v.....5&..
0x0090: 68d1 4f7d babd 27ba 84ae c5d3 750b 01bd h.o}..'.....u...
0x00a0: 9c43 e10a 33a6 8df2 a9f0 c052 c7ed 2ff5 .c..3......r../.
0x00b0: bfb1 ce84 edfc c141 6dad fa19 0702 62a7 .......am.....b.
0x00c0: 306c db6b 2eea 824e eea5 acd7 f92e 6de3 0l.k...n......m.
0x00d0: 85d0 222d f8bf 9051 2c37 93c8 506d 5cb5 .."-...q,7..pm\.
0x00e0: 3b4a 2a80 d027 49f2 c996 d2d9 a9eb c1c4 ;j*..'i.........
0x00f0: 7719 c615 8486 d84c e42d 0ba3 698c w......l.-..i.
00:39:15.124648 ip 169.144.0.1.39406 > compute-0-1.example.com.ssh: flags [.], ack 188, win 13971, options [nop,nop,ts val 22718260 ecr 90716591], length 0
0x0000: 0800 27f4 f935 0a00 2700 0000 0800 4510 ..'..5..'.....e.
0x0010: 0034 6b70 4000 4006 7c0e a990 0001 a990 root@compute-0-1 @.|.......
0x0020: 0014 99ee 0016 b684 570a 5695 8b17 8010 ........w.v.....
0x0030: 3693 7c0e 0000 0101 080a 015a a734 0568 6.|........z.4.h
0x0040: 39af
.......................................................................

这就是本文的全部内容,我希望您能了解如何使用 tcpdump 命令捕获和分析 tcp/ip 数据包。请分享你的反馈和评论。

via: https://www.linuxtechi.com/capture-analyze-packets-tcpdump-command-linux/

作者:pradeep kumar

选题:lujun9972

译者:ypingcn

校对:wxy

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。