当主机名有多个 IP 地址时,ping 如何工作?

当主机名有多个 IP 地址时,ping 如何工作?

例如google.com至少有这些ip:

74.125.225.49
74.125.225.51
74.125.225.81

ping只是随机挑选其中一个吗?

答案1

答案是,这取决于您的 DNS 解析器如何设置,以及相关域的 DNS 服务器如何设置。

ping 源主机上的 DNS 解析器将查阅操作系统和网络配置,以查找要 ping 的主机。如果这是一台新主机(您之前从未查找过该主机),DNS 查询序列将从头到尾进行。

A 记录的数量和这些记录的内容以及返回的顺序取决于目标 ping 目标域的名称服务器。这个过程是另一个讨论。

您的 DNS 客户端将从 A 记录中返回的 IP 之一中选择,并且您的 ping 将开始向该目标 IP 发送 IMCP 回显请求消息。

您的本地操作系统可能会缓存一个或多个响应一段时间,通常但并非总是按照 A 记录中指定的 TTL 进行缓存。DNS 解析器中还有另一个缓存机会,同样,它通常但并非总是遵循 TTL。

最后一个问题是某些 DNS 客户端执行的所谓排序。请参阅:

http://www.tylek.org/?p=33


答案2

它只会选择其中一个。这并不是完全随机的 —— 例如,如果其中一个在同一个本地网络上,它通常会选择那个。

答案3

PING 过程

    The source host generates an ICMP protocol data unit.
    The ICMP PDU is encapsulated in an IP datagram, with the source and destination IP addresses in the IP header. At this point the datagram is most properly referred to as an ICMP ECHO datagram, but we will call it an IP datagram from here on since that's what it looks like to the networks it is sent over.
    The source host notes the local time on it's clock as it transmits the IP datagram towards the destination. Each host that receives the IP datagram checks the destination address to see if it matches their own address or is the all hosts address (all 1's in the host field of the IP address).
    If the destination IP address in the IP datagram does not match the local host's address, the IP datagram is forwarded to the network where the IP address resides.
    The destination host receives the IP datagram, finds a match between itself and the destination address in the IP datagram.
    The destination host notes the ICMP ECHO information in the IP datagram, performs any necessary work then destroys the original IP/ICMP ECHO datagram.
    The destination host creates an ICMP ECHO REPLY, encapsulates it in an IP datagram placing it's own IP address in the source IP address field, and the original sender's IP address in the destination field of the IP datagram.
    The new IP datagram is routed back to the originator of the PING. The host receives it, notes the time on the clock and finally prints PING output information, including the elapsed time.

重复上述过程,直到所有请求的 ICMP ECHO 数据包都已发送且其响应已收到,或者默认的 2 秒超时已到期。默认的 2 秒超时是发起 PING 的主机本地的,而不是数据报中的生存时间值。

更多的:http://www.inetdaemon.com/tools/ping/how_ping_works.shtml

相关内容