国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 服務(wù)器 > Linux服務(wù)器 > 正文

在Linux中使用tcpdump命令捕獲與分析數(shù)據(jù)包詳解

2024-09-05 23:05:05
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

前言

tcpdump 是一個(gè)有名的命令行數(shù)據(jù)包分析工具。我們可以使用 tcpdump 命令捕獲實(shí)時(shí) TCP/IP 數(shù)據(jù)包,這些數(shù)據(jù)包也可以保存到文件中。之后這些捕獲的數(shù)據(jù)包可以通過(guò) tcpdump 命令進(jìn)行分析。tcpdump 命令在網(wǎng)絡(luò)層面進(jìn)行故障排除時(shí)變得非常方便。

tcpdump 在大多數(shù) Linux 發(fā)行版中都能用,對(duì)于基于 Debian 的Linux,可以使用 apt 命令安裝它。

# apt install tcpdump -y

在基于 RPM 的 Linux 操作系統(tǒng)上,可以使用下面的 yum 命令安裝 tcpdump。

# yum install tcpdump -y

當(dāng)我們?cè)跊](méi)用任何選項(xiàng)的情況下運(yùn)行 tcpdump 命令時(shí),它將捕獲所有接口的數(shù)據(jù)包。因此,要停止或取消 tcpdump 命令,請(qǐng)鍵入 ctrl+c。在本教程中,我們將使用不同的實(shí)例來(lái)討論如何捕獲和分析數(shù)據(jù)包。

示例:1)從特定接口捕獲數(shù)據(jù)包

當(dāng)我們?cè)跊](méi)用任何選項(xiàng)的情況下運(yùn)行 tcpdump 命令時(shí),它將捕獲所有接口上的數(shù)據(jù)包,因此,要從特定接口捕獲數(shù)據(jù)包,請(qǐng)使用選項(xiàng) -i,后跟接口名稱。

語(yǔ)法:

# tcpdump -i {接口名}

假設(shè)我想從接口 enp0s3 捕獲數(shù)據(jù)包。

輸出將如下所示,

tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes06: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 38006: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 22006: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 22006: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 006: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 7206: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^C109930 packets captured110065 packets received by filter133 packets dropped by kernel[[email protected] ~]#

示例:2)從特定接口捕獲特定數(shù)量數(shù)據(jù)包

假設(shè)我們想從特定接口(如 enp0s3)捕獲 12 個(gè)數(shù)據(jù)包,這可以使用選項(xiàng) -c {數(shù)量} -I {接口名稱} 輕松實(shí)現(xiàn)。

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

上面的命令將生成如下所示的輸出,

Linux,tcpdump,命令捕獲,分析數(shù)據(jù)包

N-Number-Packsets-tcpdump-interface

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

使用 -D 選項(xiàng)顯示 tcpdump 命令的所有可用接口,

[root@compute-0-1 ~]# tcpdump -D1.enp0s32.enp0s83.ovs-system4.br-int5.br-tun6.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-2811.qvoa692e993-2812.qvba692e993-2813.tapa692e993-2814.vxlan_sys_478915.any (Pseudo-device that captures on all interfaces)16.lo [Loopback][[email protected] ~]#

我正在我的一個(gè) openstack 計(jì)算節(jié)點(diǎn)上運(yùn)行 tcpdump 命令,這就是為什么在輸出中你會(huì)看到數(shù)字接口、標(biāo)簽接口、網(wǎng)橋和 vxlan 接口。

示例:4)捕獲帶有可讀時(shí)間戳的數(shù)據(jù)包(-tttt 選項(xiàng))

默認(rèn)情況下,在 tcpdump 命令輸出中,不顯示可讀性好的時(shí)間戳,如果您想將可讀性好的時(shí)間戳與每個(gè)捕獲的數(shù)據(jù)包相關(guān)聯(lián),那么使用 -tttt 選項(xiàng),示例如下所示,

[[email protected] ~]# tcpdump -c 8 -tttt -i enp0s3tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes2018-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 1882018-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 02018-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 82018-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 02018-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 23202018-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 02018-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 212018-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 08 packets captured134 packets received by filter69 packets dropped by kernel[[email protected] ~]#

示例:5)捕獲數(shù)據(jù)包并將其保存到文件(-w 選項(xiàng))

使用 tcpdump 命令中的 -w 選項(xiàng)將捕獲的 TCP/IP 數(shù)據(jù)包保存到一個(gè)文件中,以便我們可以在將來(lái)分析這些數(shù)據(jù)包以供進(jìn)一步分析。

語(yǔ)法:

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

注意:文件擴(kuò)展名必須為 .pcap。

假設(shè)我要把 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 enp0s3tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes^C841 packets captured845 packets received by filter0 packets dropped by kernel[root@compute-0-1 ~]# lsanaconda-ks.cfg enp0s3-26082018.pcap[root@compute-0-1 ~]#

捕獲并保存大小大于 N 字節(jié)的數(shù)據(jù)包。

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

捕獲并保存大小小于 N 字節(jié)的數(shù)據(jù)包。

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

示例:6)從保存的文件中讀取數(shù)據(jù)包(-r 選項(xiàng))

在上面的例子中,我們已經(jīng)將捕獲的數(shù)據(jù)包保存到文件中,我們可以使用選項(xiàng) -r 從文件中讀取這些數(shù)據(jù)包,例子如下所示,

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

用可讀性高的時(shí)間戳讀取包內(nèi)容,

[root@compute-0-1 ~]# tcpdump -tttt -r enp0s3-26082018.pcapreading 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 1242018-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 81358717], length 02018-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 val 81352560 ecr 81353913], length 02018-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 81358922 ecr 81317504], length 02018-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 14482018-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,nop,TS val 81359114 ecr 81350901], length 5082018-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 81352753 ecr 81359114], length 0.........................................................................................................................

示例:7)僅捕獲特定接口上的 IP 地址數(shù)據(jù)包(-n 選項(xiàng))

使用 tcpdump 命令中的 -n 選項(xiàng),我們能只捕獲特定接口上的 IP 地址數(shù)據(jù)包,示例如下所示,

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

上述命令輸出如下,

tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes22: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 18822: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 022: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 36422: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 022: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 34022: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 022: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 34022: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 022: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 34022: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 022: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 選項(xiàng)捕獲 N 個(gè) IP 地址包,

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

示例:8)僅捕獲特定接口上的 TCP 數(shù)據(jù)包

在 tcpdump 命令中,我們能使用 tcp 選項(xiàng)來(lái)只捕獲 TCP 數(shù)據(jù)包,

[root@compute-0-1 ~]# tcpdump -i enp0s3 tcptcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes22: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 18822: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 022: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 36422: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 022: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 34022: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 022: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 34022: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 022: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)從特定接口上的特定端口捕獲數(shù)據(jù)包

使用 tcpdump 命令,我們可以從特定接口 enp0s3 上的特定端口(例如 22)捕獲數(shù)據(jù)包。

語(yǔ)法:

# tcpdump -i {interface-name} port {Port_Number}
[root@compute-0-1 ~]# tcpdump -i enp0s3 port 22tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes22: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 18822: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 022: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 38822: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 022: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 36422: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 022: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)在特定接口上捕獲來(lái)自特定來(lái)源 IP 的數(shù)據(jù)包

在 tcpdump 命令中,使用 src 關(guān)鍵字后跟 IP 地址,我們可以捕獲來(lái)自特定來(lái)源 IP 的數(shù)據(jù)包,

語(yǔ)法:

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

例子如下,

[root@compute-0-1 ~]# tcpdump -n -i enp0s3 src 169.144.0.10tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes23: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 023: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 023: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 023: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 023: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 023: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 023: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 023: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 023: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 023: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^C10 packets captured12 packets received by filter0 packets dropped by kernel

示例:11)在特定接口上捕獲來(lái)自特定目的 IP 的數(shù)據(jù)包

語(yǔ)法:

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

[root@compute-0-1 ~]# tcpdump -n -i enp0s3 dst 169.144.0.1tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes23: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 18823: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 22023: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 19623: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 19623: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 19623: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)捕獲兩臺(tái)主機(jī)之間的 TCP 數(shù)據(jù)包通信

假設(shè)我想捕獲兩臺(tái)主機(jī) 169.144.0.1 和 169.144.0.20 之間的 TCP 數(shù)據(jù)包,示例如下所示,

[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 命令只捕獲兩臺(tái)主機(jī)之間的 SSH 數(shù)據(jù)包流,

[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)捕獲兩臺(tái)主機(jī)之間(來(lái)回)的 UDP 網(wǎng)絡(luò)數(shù)據(jù)包

語(yǔ)法:

# 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)捕獲十六進(jìn)制和 ASCII 格式的數(shù)據(jù)包

使用 tcpdump 命令,我們可以以 ASCII 和十六進(jìn)制格式捕獲 TCP/IP 數(shù)據(jù)包,

要使用 -A 選項(xiàng)捕獲 ASCII 格式的數(shù)據(jù)包,示例如下所示:

[root@compute-0-1 ~]# tcpdump -c 10 -A -i enp0s3tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes00: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 188E...[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 0root@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 0root@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 0root@compute-0-1 @.............(.c.$g.......Se......fW..e....................................................................................................................................................

要同時(shí)以十六進(jìn)制和 ASCII 格式捕獲數(shù)據(jù)包,請(qǐng)使用 -XX 選項(xiàng)。

[root@compute-0-1 ~]# tcpdump -c 10 -XX -i enp0s3tcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes00: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 1880x0000: 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..Z0x0040: a731 adb7 58b6 1a0f 2006 df67 c9b6 4479 .1..X......g..Dy0x0050: 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 00x0000: 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.h0x0040: 39af.......................................................................

這就是本文的全部?jī)?nèi)容,我希望您能了解如何使用 tcpdump 命令捕獲和分析 TCP/IP 數(shù)據(jù)包。請(qǐng)分享你的反饋和評(píng)論。

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

作者:Pradeep Kumar

選題:lujun9972

譯者:ypingcn

校對(duì):wxy

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)VEVB武林網(wǎng)的支持。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到服務(wù)器教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 宜川县| 两当县| 改则县| 江川县| 博白县| 抚顺县| 喀喇| 墨玉县| 广河县| 呈贡县| 宁陵县| 清流县| 张家口市| 文登市| 高唐县| 娄底市| 岳普湖县| 忻城县| 丽水市| 闽清县| 天峻县| 观塘区| 余庆县| 绥江县| 济源市| 东台市| 庆安县| 阜阳市| 偏关县| 乌恰县| 邓州市| 高邮市| 万州区| 西丰县| 大姚县| 无极县| 兴隆县| 新绛县| 昌平区| 怀安县| 和静县|