The ping utility works above the network layer and DNS works in the application layer.

If we try ping www.google.com, how does it resolve the IP address of GOOGLE since the DNS is above these layers?

有帮助吗?

解决方案

ICMP (the protocol) may operate above IP, alongside TCP but a ping program itself almost certainly still uses the normal methods for name resolution, be that DNS, hosts file or resolv.conf.

For example, the ping program located here calls on gethostbyname() to turn DNS names into IP addresses.

其他提示

Certainly on windows computers, ping also uses LLMNR (Link-Local Multicast Name Resolution) to perform hostname resolution. A host may be pinged just fine while other services still fail if a computer is only known by LLMNR and the failing service relies on DNS. Vice versa: DNS may work but ping fails

Hostnames are still resolved through DNS, after that ping uses ICMP for the actual communication. You can try changing the DNS configs to invalid servers and see that ping won't work with hostnames.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top