ping 与 dig 的 TTL

ping 与 dig 的 TTL

当我运行时ping google.com,我得到ttl的值是55

64 bytes from 173.194.127.103: icmp_seq=68 ttl=55 time=16.4 ms

当我运行时dig google.com @ns1.google.com.,它得到TTL的值是300

google.com.     300 IN  A   173.194.127.34

为什么我得到两个不同的值TTL,以及哪一个值在什么情况下是相关的?

答案1

TTL与 DNS 相比,with具有ping完全不同的含义。

对于 DNS,它表示记录在被认为太旧之前可以缓存多长时间。 的值表示ping数据包在被丢弃之前可以在不同的网络上进行多少次跳转。到达目标路径上的每一次跳转都会将此值减 1,如果跳转次数过多,数据包将被丢弃。这是为了防止在配置错误的情况下数据包永无止境的循环。

我也同意,像谷歌这样的庞然大物必须竭尽全力并使用一切可用的技巧才能尽快给出答复,这不是研究此事的好例子。

答案2

来自联机帮助页的有关 ping TTL 的附加上下文。

TTL DETAILS
       The  TTL  value  of  an  IP  packet represents the maximum number of IP
       routers that the packet can go through before being  thrown  away.   In
       current  practice  you can expect each router in the Internet to decre-
       ment the TTL field by exactly one.

       The TCP/IP specification states that the  TTL  field  for  TCP  packets
       should  be set to 60, but many systems use smaller values (4.3 BSD uses
       30, 4.2 used 15).

       The maximum possible value of this field is 255, and most Unix  systems
       set the TTL field of ICMP ECHO_REQUEST packets to 255.  This is why you
       will find you can ‘‘ping’’ some hosts, but not  reach  them  with  tel-
       net(1) or ftp(1).

       In  normal  operation  ping  prints  the  ttl  value from the packet it
       receives.  When a remote system receives a ping packet, it can  do  one
       of three things with the TTL field in its response:

       · Not  change  it;  this  is  what Berkeley Unix systems did before the
         4.3BSD Tahoe release. In this case the  TTL  value  in  the  received
         packet  will  be  255  minus  the number of routers in the round-trip
         path.

       · Set it to 255; this is what current Berkeley  Unix  systems  do.   In
         this  case the TTL value in the received packet will be 255 minus the
         number of routers in the path from the remote system to  the  pinging
         host.

       · Set it to some other value. Some machines use the same value for ICMP
         packets that they use for TCP packets, for example either 30  or  60.
         Others may use completely wild values.

相关内容