tcpdump icmp ip報文分片

介紹

主要演示了tcpdump捕捉icmp報文以及用ping命令指定icmp長度後ip分組的查看。php

A發起正常包ping

C:\Users\yaxia>ping 10.70.30.60
正在 Ping 10.70.30.60 具備 32 字節的數據:
來自 10.70.30.60 的回覆: 字節=32 時間<1ms TTL=64
來自 10.70.30.60 的回覆: 字節=32 時間<1ms TTL=64
來自 10.70.30.60 的回覆: 字節=32 時間<1ms TTL=64
來自 10.70.30.60 的回覆: 字節=32 時間<1ms TTL=64

10.70.30.60 的 Ping 統計信息:
    數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計時間(以毫秒爲單位):
    最短 = 0ms,最長 = 0ms,平均 = 0ms

B 端查看結果

root@php56:/home/tb# tcpdump -ntv  -i enp0s3 icmp
tcpdump: listening on enp0s3, link-type EN10MB (Ethernet), capture size 262144 bytes
IP (tos 0x0, ttl 128, id 27746, offset 0, flags [none], proto ICMP (1), length 60)
    10.70.30.47 > 10.70.30.60: ICMP echo request, id 1, seq 4795, length 40
IP (tos 0x0, ttl 64, id 30075, offset 0, flags [none], proto ICMP (1), length 60)
    10.70.30.60 > 10.70.30.47: ICMP echo reply, id 1, seq 4795, length 40
IP (tos 0x0, ttl 128, id 27748, offset 0, flags [none], proto ICMP (1), length 60)
    10.70.30.47 > 10.70.30.60: ICMP echo request, id 1, seq 4796, length 40
IP (tos 0x0, ttl 64, id 30127, offset 0, flags [none], proto ICMP (1), length 60)
    10.70.30.60 > 10.70.30.47: ICMP echo reply, id 1, seq 4796, length 40
IP (tos 0x0, ttl 128, id 27750, offset 0, flags [none], proto ICMP (1), length 60)
    10.70.30.47 > 10.70.30.60: ICMP echo request, id 1, seq 4797, length 40
IP (tos 0x0, ttl 64, id 30365, offset 0, flags [none], proto ICMP (1), length 60)
    10.70.30.60 > 10.70.30.47: ICMP echo reply, id 1, seq 4797, length 40
IP (tos 0x0, ttl 128, id 27752, offset 0, flags [none], proto ICMP (1), length 60)
    10.70.30.47 > 10.70.30.60: ICMP echo request, id 1, seq 4798, length 40
IP (tos 0x0, ttl 64, id 30534, offset 0, flags [none], proto ICMP (1), length 60)
    10.70.30.60 > 10.70.30.47: ICMP echo reply, id 1, seq 4798, length 40

A發送大於MTU的數據包

C:\Users\yaxia>ping 10.70.30.60 -l 1473

正在 Ping 10.70.30.60 具備 1473 字節的數據:
來自 10.70.30.60 的回覆: 字節=1473 時間<1ms TTL=64
來自 10.70.30.60 的回覆: 字節=1473 時間<1ms TTL=64
來自 10.70.30.60 的回覆: 字節=1473 時間<1ms TTL=64
來自 10.70.30.60 的回覆: 字節=1473 時間<1ms TTL=64

10.70.30.60 的 Ping 統計信息:
    數據包: 已發送 = 4,已接收 = 4,丟失 = 0 (0% 丟失),
往返行程的估計時間(以毫秒爲單位):
    最短 = 0ms,最長 = 0ms,平均 = 0ms

B接收結果(能夠看到ip包多了一倍)

P (tos 0x0, ttl 128, id 27801, offset 0, flags [+], proto ICMP (1), length 1500)
    10.70.30.47 > 10.70.30.60: ICMP echo request, id 1, seq 4799, length 1480
IP (tos 0x0, ttl 128, id 27801, offset 1480, flags [none], proto ICMP (1), length 21)
    10.70.30.47 > 10.70.30.60: ip-proto-1
IP (tos 0x0, ttl 64, id 10022, offset 0, flags [+], proto ICMP (1), length 1500)
    10.70.30.60 > 10.70.30.47: ICMP echo reply, id 1, seq 4799, length 1480
IP (tos 0x0, ttl 64, id 10022, offset 1480, flags [none], proto ICMP (1), length 21)
    10.70.30.60 > 10.70.30.47: ip-proto-1
IP (tos 0x0, ttl 128, id 27803, offset 0, flags [+], proto ICMP (1), length 1500)
    10.70.30.47 > 10.70.30.60: ICMP echo request, id 1, seq 4800, length 1480
IP (tos 0x0, ttl 128, id 27803, offset 1480, flags [none], proto ICMP (1), length 21)
    10.70.30.47 > 10.70.30.60: ip-proto-1
IP (tos 0x0, ttl 64, id 10189, offset 0, flags [+], proto ICMP (1), length 1500)
    10.70.30.60 > 10.70.30.47: ICMP echo reply, id 1, seq 4800, length 1480
IP (tos 0x0, ttl 64, id 10189, offset 1480, flags [none], proto ICMP (1), length 21)
    10.70.30.60 > 10.70.30.47: ip-proto-1
IP (tos 0x0, ttl 128, id 27805, offset 0, flags [+], proto ICMP (1), length 1500)
    10.70.30.47 > 10.70.30.60: ICMP echo request, id 1, seq 4801, length 1480
IP (tos 0x0, ttl 128, id 27805, offset 1480, flags [none], proto ICMP (1), length 21)
    10.70.30.47 > 10.70.30.60: ip-proto-1
IP (tos 0x0, ttl 64, id 10418, offset 0, flags [+], proto ICMP (1), length 1500)
    10.70.30.60 > 10.70.30.47: ICMP echo reply, id 1, seq 4801, length 1480
IP (tos 0x0, ttl 64, id 10418, offset 1480, flags [none], proto ICMP (1), length 21)
    10.70.30.60 > 10.70.30.47: ip-proto-1
IP (tos 0x0, ttl 128, id 27807, offset 0, flags [+], proto ICMP (1), length 1500)
    10.70.30.47 > 10.70.30.60: ICMP echo request, id 1, seq 4802, length 1480
IP (tos 0x0, ttl 128, id 27807, offset 1480, flags [none], proto ICMP (1), length 21)
    10.70.30.47 > 10.70.30.60: ip-proto-1
IP (tos 0x0, ttl 64, id 10429, offset 0, flags [+], proto ICMP (1), length 1500)
    10.70.30.60 > 10.70.30.47: ICMP echo reply, id 1, seq 4802, length 1480
IP (tos 0x0, ttl 64, id 10429, offset 1480, flags [none], proto ICMP (1), length 21)
    10.70.30.60 > 10.70.30.47: ip-proto-1

摘出來一個被分片的ip數據包

IP (tos 0x0, ttl 128, id 27801, offset 0, flags [+], proto ICMP (1), length 1500)
    10.70.30.47 > 10.70.30.60: ICMP echo request, id 1, seq 4799, length 1480
IP (tos 0x0, ttl 128, id 27801, offset 1480, flags [none], proto ICMP (1), length 21)
    10.70.30.47 > 10.70.30.60: ip-proto-1
簡單解釋
  1. id都爲27081,說明爲同一個ip數據報的分片。
  2. 第一個ip分組的offset 爲0,第二個爲1480.
  3. 第一個ip分組的flags爲+,實則設置了MF標誌,表示後續還有分片,第二個flag爲none
  4. 第一個ip分組長度爲1500,第二個爲21
-l 1473字節的由來
  1. win下查看A端mtu算法

    C:\Users\yaxia>netsh interface ipv4 show subinterfaces
    
       MTU  MediaSenseState   傳入字節  傳出字節      接口
    ------  ---------------  ---------  ---------  -------------
    4294967295                1   31577369      21149  Loopback Pseudo-Interface 1
      1500                1  10271737813  4348038074  以太網
      1500                1       4944    9536968  VirtualBox Host-Only Network
  2. B端mtu ifconfig數組

    enp0s3    Link encap:Ethernet  HWaddr 08:00:27:ce:14:39  
              inet addr:10.70.30.60  Bcast:10.70.31.255  Mask:255.255.254.0
              inet6 addr: fe80::a00:27ff:fece:1439/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:3130176 errors:0 dropped:0 overruns:0 frame:0
              TX packets:171929 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:361713379 (361.7 MB)  TX bytes:124807829 (124.8 MB)
  3. 通常ip頭部一般20個字節(選項40個字節爲0的狀況,因此說最長ip頭部60個字節),以太網的幀MTU最大爲1500字節,因此承載的ip的數據部分最大爲1480字節。icmp頭部報文長度爲8字節。若是咱們用ip數據報封裝一個長度爲1480+1的icmp報文,那就須要1481-8=1473字節大小的icmp數據部分大小。因此 -l 爲1473。若是是封裝正常的ip報文,好比4000個字節,能夠參考如下算法:4000字節中,正常20字節爲ip包頭,剩下3980字節爲數據,須要分紅3個ip片(假設鏈路層MTU爲1500),那麼第一個分片的片偏移offset就是0,表示該分片在3980的第0位開始,第1479位結束。第二個ip片的片偏移爲185(1480/8),表示該分片開始的位置在原來ip的第1480位,結束在2959。第三片的片偏移爲370(2960/8),表示開始的時候是2960位,結束的時候在3979位。也不可貴出,ip數組分組的分片的單位是8個字節。
相關文章
相關標籤/搜索