How does ping work when a host name has multiple ip addresses?

For example, google.com has at least these ip:

74.125.225.49
74.125.225.51
74.125.225.81

Does ping just pick one of them randomly?


The answer is it depends on how your DNS resolver is setup and also how the DNS server for the domain in question is set up.

The DNS resolver on your ping source host will consult the OS and network configuration to lookup the host you want to ping. If this is a new host, one for which you haven't previously done a lookup, the DNS query sequence will go from start to finish.

The number of A records and contents of those records as well as what order they are are returned depends on the name servers for the target ping destination domain. This process is a whole other discussion.

Your DNS client will pick one of those IPs returned in the A records and your ping will start sending IMCP echo-request messages to that destination IP.

Your local OS may cache one or more of the responses for some period of time, typically but not always the TTL specified in the A record. There is also another caching opportunity at your DNS resolver, again, which typically but not always will follow the TTL.

One final wrinkle is the so-called sort ordering done by some DNS clients. See:

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



It just picks one of them. It's not quite random -- for example, if one of them is on the same local network, it will typically pick that one.