当前位置: 代码迷 >> 综合 >> Azure虚拟机中使用Tracert/Traceroute/MTR(My Traceroute)的原理讨论
  详细解决方案

Azure虚拟机中使用Tracert/Traceroute/MTR(My Traceroute)的原理讨论

热度:64   发布时间:2023-12-14 21:56:57.0

命令:mtrXXX.XXX.XXX.XXX

效果:

Machine generated alternative text:we. 751 Dancent0S65 (?.?.?.?) *solver: Received error response 2. 24.? 3.4 1.4 ?.6 2.3 3.2 2.? 3.? 2.8 1.9 2.7 2.3 3.5 ?.4 3.1 2.9 2.4 6.2 ?.6 (server failure)er of fields My tracerM1te qu it Packets Fri Jan 8 2?16 Pings Last 6 3. Wrst StDev 3. 5. 6. 7. 8. g. 16 . 1?3.g.8 18 18B.149.129.157 218.3?.112.137 22?.181.?.57 bj 141-133-238. bj telecom. net 196.78.126.106. static .bjtelecom . net Loss* 6?. 38. 73. Snt 47 47 47 46 46 46 Avg Best 4 13 . 14 . 7 6

 

如果加上-n参数可以显示IP而不是反向解析成域名:

例如mtr -nXXX.XXX.XXX.XXX

Machine generated alternative text:[ve .75] Dancentos65 Keys: Help 4. 777 19.9 35 1.4 29 13.8 13.8 79.1* 196 .129 .78 .199 2.4 3.4 (G.G.G.G) Display mode Resta rt statistics Orde r fields my quit t race route sun Jan 19 2916 Packets Loss* Snt Host 777 777 777 . 193.9.8.2G . 189 .149.129.157 . 229 .181 . 219.142.1.157 . 219.141.139.154 19. Las t Pings Avg Best 1.7 Wrst StDev 9.2

 

mtr的工作原理:

利用IP报文头部的TTL值来进行探测

 

我们以目标IP为106.120.78.190为例:

抓包见附件,我们看到如下的交互过程:

Machine generated alternative text:Fr ame Number Time Date Local Adjusted 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 Time Offset 4.6975380 4.7979270 4.8982820 4.9986560 5.0992710 5.1770390 5.1791640 5.2772790 5.2891540 5.3776130 5.3810560 5.4779790 5.4818690 5.5783070 5.5808840 5.6786170 5.6811270 Sour ce 192.168.0.4 192.168.0.4 192.168.0.4 192.168.0.4 192.168.0.4 103.9.8.18 192.168 0 4 180.149.129.157 192.168 0 4 218.30.112.137 192.168 0 4 220.181.0.57 192.168 0 4 219.141.133.238 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 Destina bon 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 Protocol Name ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP Description ICMP :Echo Request Message, ICMP:Echo Request Message, ICMP :Echo Request Message, ICMP :Echo Request Message, ICMP:Echo Request Message, ICMP:Tme Exceeded Message From 192.168.0.4To 106.120.78.190 From 192,168.014 To 106.120.78.190 From 192.168.014 To 106.120.78.190 From 192.168.014 To 106.120.78.190 From 192.168.014 To 106.120.78.190 ICMP:Echo Request Message, From 192.168.0.4 To 106.120.78.190 ICMP:Tme Exceeded Message ICMP:Echo Request Message, From 192.168.0.4 To 106.120.78.190 ICMP:Tme Exceeded Message ICMP:Echo Request Message, From 192.168.0.4 To 106.120.78.190 ICMP:Tme Exceeded Message ICMP:Echo Request Message, From 192.168.0.4To 106.120.78.190 ICMP:Tme Exceeded Message ICMP:Echo Request Message, From 192.168.014 To 106.120.78.190 ICMP:Echo Reply Message, From 106.120.78.190 To 192.168.014 ICMP:Echo Request Message, From 192.168.014 To 106.120.78.190 ICMP:Echo Reply Message, From 106.120.78.190 To 192.168.014

前4个报文展开来看:

第一个:

Machine generated alternative text:Frame Number 106. 120.78. 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 168, 0 4 168, 0 4 106.120.78.190 168 0 4 168, 0 4 106.120.78.190 168 0 4 168, 0 4 106.120.78.190 168 0 4 168, 0 4 106.120.78.190 219.141.133.238 168, 0 4 168, 0 4 106.120.78.190 168 0 4 168, 0 4 168 0 4 Frame Details 01 192. 168 Time Date Local Adjusted 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 Time Offset 4.6975380 4.7979270 4.8382820 4.9986560 5.0992710 5.1770390 5.1791640 2772790 2891540 3776130 3810560 5.4779790 4818690 5.5783070 .5808840 5.6786170 5.6811270 7699750 .8612980 5.9526660 6.0440380 1354480 Source 192. 04 192.16804 192.168 0 4 192.168 0 4 192.168 0 .9.8.18 Destnaton 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 192. 106.120.78.190 192. 106.120.78.190 192. 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 Protocol Name ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP Descripton ICMP:Echo Reauest Messaae, From ICMP:Echo Request Message, From ICMP:Echo Request Message, From ICMP:Echo Request Message, From ICMP:Echo Request Message, From ICMP:Tme Exceeded Message ICMP:Echo Request Message, From ICMP:Tme Exceeded Message ICMP:Echo Request Message, From ICMP:Tme Exceeded Message ICMP:Echo Request Message, From ICMP:Tme Exceeded Message ICMP:Echo Request Message, From ICMP:Tme Exceeded Message 192. 168.0. To 192. 168.0.4 To 192. 192. 192. 103 192. 180 192. 192. 192. 192. 192. 149.129.157 218.30.112.137 220.181.0.57 106.120.78.190 106.120.78.190 192.168 0 192.168 0 4 192.168 0 4 192.168 0 4 192.168.0.4 192. 192. 192. 192. 78, 192.168. o. 192.168. o. 192.168. o. 192.168. o. 192,168.0. 4 To 4 To 4 To 4 To 4 To ICMP: ICMP: ICMP ICMP: ICMP: ICMP ICMP? Echo Request Message, From ?Echo Reply Message, From 106.120.78.190 To 192.168.014 Echo Request Message, From 192.168.014 To 106.120.78. :Echo Reply Message, From 106.120.78.190 To 192.168.014 Echo Request Message, Echo Request Message, ?Echo Request Message, ?Echo Request Message, . Echo Reouest Messaoe. x A-BC] , sourc, Packet ID 190 From 192.168.014 To 106.120.78.190 From 192.168.014 To 106.120.78.190 From 192.168.014 To 106.120.78.190 From 192.168.014 To 106.120.78.190 From 192.168.014 To 106.120.78.190 Frame : Number IS, Captured Frame Length Medi al yep e — ETHERNET Hex Details Decode As Width Ethernet: E type = Internet IP (IPv4) , DestinationAddress: [12—34—56—78 Ipv4: Src 192.168.0.4, Dest 106.120. 78.190, Next Protocol ICMP, Versions: IPv4, Internet Protocol; DifferentiatedServicesFieId: DSCP: Header Length o, Ecu. Total Length: 64 (Ox40) Identification: 40231 (Ox9D27) 1 (Oxl) checksum: 41651 (OxA2B3) SourceAddress: 192. 168. 0.4 DestinationAddress: 106. 120. 78. lcmp: Echo Request Message, From 190 20 106.120.78 0000 0006 oooc 0012 0018 001E 0024 002A 0030 0036 oosc 0042 0048 12 oo 08 oo oo oo oo oo oo 34 17 oo 27 78 oo oo oo oo oo oo oo co oo oo oo oo oo oo 78 oo oo BE oo oo oo oo oo oo 09 oo oo 08 oo oo oo oo oo oo 40 04 oo 80 oo oo oo oo oo oo 190

第二个:

Machine generated alternative text:Frame : Number 19, Captured Frame Length = 78, MediaTy-pe — ETHERNET g?Ethernet: E type = Internet IP (IPv4) , Destination?ddress: [12—34—56—78 Ipv4: Src 192.168.0.4, Dest 106.120. 78.190, Next Protocol ICMP, A-BC] , sourc Packet ID Versions: IPv4, Internet Protocol; DifferentiatedServicesFieId: DSCP: Total Length: 64 (Ox40) Identification: 40232 (Ox9D28) 2 (Ox2) Nextprotocol: ICMP, 1 checksum: 41394 (OxAIB2) SourceAddress: 192. 168. 0.4 Header Length o, Ecu: 20 Destination?ddress: 106. 120. 78. 190 lcmp: Echo Request Message, From 192.168. 106.120.78 190

第三个第四个的TTL分别为3和4。

 

即向目的端依次发TTL=1,TTL=2,TTL=3…的ICMP报文,当TTL=1时,到达第一个路由之后,就直接返回了,如果该路由没有任何返回结果,则在mtr界面上就显示为???,这也是为什么我们的结果中前4跳都显示为???,应该是对应的azure设备。

 

接着,在TTL=5的报文发出后,我们收到了103.9.8.18返回的TimeExceeded Message,即这一跳的设备返回TTL过期的错误给我们,所以也就知道了这一跳的IP地址以及可达性。

Machine generated alternative text:Find. t Color Rules Fr ame Number Time Date L Ocal Adjusted 2016/1/8 106.120.78.190 2016/1/8 106.120.78.190 2016/1/8 106.120.78.190 2016/1/8 106.120.78.190 2016 106.120.78.190 2016/1/8 106.120.78.190 2016/1/8 2016/1/8 106.120.78.190 2016/1/8 2016/1/8 106.120.78.190 2016/1/8 2016/1/8 106.120.78.190 2016/1/8 2016/1/8 106.120.78.190 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 Time Offset 4.6975380 4.7979270 4.8982820 4.9986560 5.0992710 s. oggggso 5.1770390 5.1791640 5.2772790 5.2891540 5.3776130 5.3810560 5.4779790 5.4818690 5.5783070 5.5808840 5.6786170 5.6811270 5.7699750 5.8612980 5.9526660 6.0440380 Sour ce 192.168.0.4 192.168.0.4 192.168.0.4 192.168.0.4 192.168.0.4 192.168.0.4 180.149.129.157 192.168.0.4 218.30.112.137 192.168 0 4 220.181.0157 192.168 0 4 219.141.133.238 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 192.168 04 192.168 0 4 192.168 0 4 Destina bon 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 192. 168.0.4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 192.168 0 4 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 Protocol Name ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP Description ICMP :Echo Request Message, ICMP:Echo Request Message, ICMP:Echo Request Message, ICMP:Echo Request Message, ICMP:Echo Re uest Messa e ICMP:Tme Exceeded Messaae ICMP:Echo Request Message, From ICMP:Tme Exceeded Message ICMP:Echo Request Message, From ICMP:Tme Exceeded Message ICMP:Echo Request Message, From ICMP:Tme Exceeded Message ICMP:Echo Request Message, From ICMP:Tme Exceeded Message ICMP:Echo Request Message, From From 192.168.0. From 192.168.0. From 192.168.0. From 192,168.0. From 192.168.0. 192,168.0. 192.168. o. 192.168. o. 192.168. o. 192.168.0. 4 To 4 To 4 To 4 To 4 To 4 To 4 To 4 To 4 To 4 To ICMP:Echo Reply Message, From 106.120.78.190 To 192.168.014 ICMP:Echo Request Message, From 192.168.014 To 106.120.78.190 ICMP:Echo Reply Message, From 106.120.78.190 To 192.168.014 ICMP:Echo Request Message, From 192.168.014 To 106.120.78.190 ICMP:Echo Request Message, From 192.168.014 To 106.120.78.190 ICMP:Echo Request Message, From 192.168.014 To 106.120.78.190 ICMP:Echo Request Message, From 192.168.014 To 106.120.78.190

依次类推,继续发送TTL+1的ICMP报文,直到真正我们mtr的目的IP返回了一个ICMP响应报文:

Machine generated alternative text:Fr ame Number 192.168 192.168 168, 0 4 168 0 4 168 0 4 168, 0 4 168, 0 4 168, 0 4 168, 0 4 168, 0 4 219.141.133.238 168 0 4 168 0 4 168 0 4 168, 0 4 168, 0 4 168, 0 4 Time Date Local Adjusted 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016/1/8 2016 2016/1/8 2016/1/8 2016/1/8 2016/1/8 Time Offset 4.6975380 4.7979270 4.8982820 4.9986560 5.0992710 5.1770390 5.1791640 2772790 .2891540 .3776130 13810560 5.4779790 .4818690 5. 5783070 s. 5808840 5.6786170 5.6811270 7699750 .8612980 Sour ce 192.168 0 4 192.168 0 4 192.168 0 .9.8.18 Destina bon 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 106.120.78.190 192. 106.120.78.190 192. 106.120.78.190 192. 106.120.78.190 192. 106.120.78.190 192. 106.120.78.190 192. 106.120.78. Igo 192. 106.120.78.190 106.120.78.190 Protocol Name ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP ICMP Description ICMP :Echo Request Message, ICMP:Echo Request Message, ICMP :Echo Request Message, ICMP :Echo Request Message, ICMP:Echo Request Message, From 192.168.0.4To 106.120.78.190 From 192.168.014 To 106.120.78.190 From 192.168.014 To 106.120.78.190 From 192.168.014 To 106.120.78.190 From 192.168.014 To 106.120.78.190 103 192. 180 192. 192. 192. 192. 192. 192. 192. 149.129.157 218.30.112.137 220.181.0.57 106. 120.78. Igo 106.120.78.190 ICMP:Tme Exceeded Message ICMP:Echo Request Message, From 192.168.0.4 To 106.120.78.190 ICMP:Tme Exceeded Message ICMP:Echo Request Message, From 192.168.0.4 To 106.120.78.190 ICMP:Tme Exceeded Message ICMP:Echo Request Message, From 192.168.0.4 To 106.120.78.190 ICMP:Tme Exceeded Message ICMP:Echo Request Message, From 192.168.014 To 106.120.78.190 ICMP:Tme Exceeded Message ICMP:Echo Re uestMessa e From 192,168.014 To 106.120.78.190 ICMP:Echo Messaae, From 106. 120.78. 190 To 192. 168.0.4 ICMP:Echo Request Message, From 192.168.014 To 106.120.78. Igo ICMP:Echo Reply Message, From 106.120.78.190 To 192.168.014 ICMP:Echo Request Message, From 192.168.014 To 106.120.78.190 ICMP:Echo Request Message, From 192.168.014 To 106.120.78.190

然后再重新开始TTL=1的新一轮探测。

上面实验的前提是为虚拟机指定了PIP,这样回显的ICMPTime Exceeded Message才能够到达主机从而知道每一跳的地址。

 

在Azure虚拟机中做了一下tracert,发现原理和mtr相同,配置PIP后同样可以显示出结果:

Machine generated alternative text:106 .120.?8.190 racing route to 196.78 .126.106 . static .b?telecom.net uer a maximum OF 30 hops: 30 ms 30 ms 36 ms 42 ms 43 ms 32 ms 31 ms [106.120.?8.190] 36 42 31 Request timed out. Request timed out. Request timed out. Request timed out. 42.159.128.80 180.149.129.15? Request timed out. 219.142.1.15? b?141-158-1?4.b?te1ecom.net [219 .141 .158.174] ms 196.78 .126.106 . static .b?telecom.net [106 .120.78. 90] race complete . Machine generated alternative text:www.baidu.com racing route to www.a.shifen.com [220.181 .111.188] uer a maximum OF 30 hops: 220.181.1?.150 30 ms 220.181.111.188 Request timed Request timed Request timed Request timed 42.159.128.80 25 26 Request Request Request Request t imed t imed t imed out. out. out. out. out. out. out. race 26 ms 30 ms complete . timed out.

同时,从抓包也可以看出,tracert计算延迟时间是通过发送ICMP报文与收到Time Exceeded Message的时间差来计算的,例如:

Machine generated alternative text:www.baidu.com racing route to www.a.shifen.com [220.181 .112.244] uer a maximum OF 30 hops: 180.149.129.15? 220.181.112.244 Request timed out. Request timed out. Request timed out. Request timed out. 42.159.128.80 Request timed out. Request timed out. 220.181.1?.22 Request timed out. race 30 ms 30 ms complete . 30 ms 30 ms 32 35

看到第6跳,两次超时加一次32ms,从抓包来看,前两次没有收到Time Exceeded Message:

Machine generated alternative text:Frame Number 221181.112244 221181.112244 180.149.1291157 180.149.1291157 1007 180.149.1291157 1019 180.149.1291157 1044 221181.112244 1077 221181.112244 F『ame Details IPV4 : 5 EC 510 : 220 . 1巳1 . 112 . 2?4 Time 08t巳 Local Adi」Sted :02 PM 1!9i2016 10:01 :03 PM 1!9i2016 10:01 10:01:07 PM 11912016 : 15 PM 1!9i2016 10:01 : 15 PM 1!9i2016 10:01 : 15 PM 1!9i2016 10:01 :17 PM 1!9i2016 10:01 : 18 PM 1!9i2016 10:01 :21 PM 1!9i2016 10:01 :25 PM 1!9i2016 10:01 10 . . . 巳, Dest Time Offset 82.6730674 84.1707991 88.1141271 96.0437222 96.076190 96.102441 97.6067096 99.1037877 101.5457161 105.5526304 220 . 1B 1 . 112 . 2 , Header , ECN : 42.159.128.80 42.159.128.80 Destination 10.0.?8 10.0.?8 10.0.?8 10.0.?8 10.0.?8 10.0.?8 protocol Name ICMP ICMP ICMP ICMP 10.0.?8 10.0.?8 10.0.?8 10.0.?8 Ne Xt ength ICMP:Destination unreachable Message, Port Unreachable, 42.159.128.80: 137 ICMP:Destination unreachable Message, Port Unreachable, 42.159.128.80: 137 ICMp:Echo Re Messa 巳 From 10.0.?8 TO 220.181.1121244 ICMp:Echo Request Message, From 10.0.?8 TO 220.181.112.244 ICMP : Time Exceeded Message ICMP:Destination unreachable Message, Port Unreachable, 180.149.129.157: 137 ICMP:Destination unreachable Message, Port Unreachable, 180.149.129.157: 137 ICMP:Destination unreachable Message, Port Unreachable, 180.149.129.157: 137 ICMP ICMP ICMP ICMP ICMP ICMP Pa ICMp:Echo Request Message, From 10.10 ICMp:Echo Request Message, From 10.10 .8 TO 220.181.1121244 .8 TO 220.181.1121244 P C 01 ICMP , ket Il ^ ?.:: Decode IPv4 , Int PEO CO 1 ; 01 1 1 1 1 : DSCP : TotalLength: 92 ( ) Ident 1 f 1 10 n: 1B 2 6 ( 口x72 2 ) Fra : 口X口 0口口口 口口口A 001 口口IE 口口2巳 口口3 2 口口3 C 口口?6 口口5口 口口5A 口口6? 1 2 3 C C Width ? Prot OF麟 5 6 5 1 0(0乂00) B C F 7 1 7 5 C Frame Off: 14 (OXOE) . VX 14 [41 p 0 . 前西)欠鄱i殳有返叵 Time Exceeded Message 第三次的岌送和返叵日寸同 差力0.032468s , 即32ms B 5 3 1 T TOL iV巳 : 6 (OX 6 ) X P t CO 1 : I CMP , Checksum: ( 口X口 ) TTL=6射疵第6跳 1(口xl) Dest 1 10 : 2 20 . 1 1 . 112 . 2 lcmp : Echo Request Message , 0m 10 . . TO

 

最后,又在虚拟机配置PIP的情况下使用traceroute进行了实验,发现traceroute的原理是发送UDP报文(也可以使用-I参数指定使用ICMP报文),同样利用TTL递增的原理,同样可以收到Time Exceeded Message的ICMP报文,但是却没有显示任何结果,原因是尽管收到了Time Exceeded Message,但是traceroute并不像mtr一样会对响应时间和丢包率进行统计,或者像tracert一样利用Time Exceeded Message的返回时间进行计算,因此当3次Time ExceededMessage收到后,traceroute就判断这个node不可达,所以在结果中就只能看到全是*的情况。

当指定-I参数时,traceroute会使用ICMP报文进行探测而非UDP,因此当到达实际要探测的目的端IP时,目的端IP会返回Echo Reply Message:

Machine generated alternative text:2016/1/10 14.4076570 106.120.78.190 2016/1/10 14.4076620 106.120.78.190 2016/1/10 14.4076660 106.120.78.190 192.168 0 192.168.0.4 192.168.0.4 ICMP ICMP ICMP :Echo Reply Message, ICMP:Echo Reply Message, ICMP:Echo Reply Message, From 106.120.78.190 To 192.168.0.4 From 106.120.781190 To 192.168.0.4 From 106.120.781190 To 192.168.0.4

此时,能够看出中间经过的跳数(但是每一跳的IP不会回显),以及到这个目的端IP的延迟:

Machine generated alternative text:[ root@anCentOS65 trace route to 196 4 7 trace route .129 .78.199 -1 -n 196.129.78.199 (196.129.78.199), 39 hops max, 69 byte packets 196.129.78.199 2.992 ms 2.894 ms 2.876 ms

而使用UDP的时候,没有ICMP的Echo Reply Message,所以探测会一直持续下去没有任何结果(知道达到最大跳数30):

Machine generated alternative text:[ root@Dancentos65 trace route to 196 4 11 12 13 14 15 16 17 18 19 29 21 22 23 24 25 26 27 28 29 39 trace route 196.129.78.199 .129.78.199 (196.129.78.199), 39 hops max, 69 byte packets

  相关解决方案