How does ping resolve ip addresses? [closed]
Asked Answered
L

3

9

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?

Laxation answered 18/6, 2013 at 5:15 Comment(0)
C
7

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.

Chamonix answered 18/6, 2013 at 5:22 Comment(3)
Do you know if ping tries to resolve dns name into ip each time the ping is sent or just at the beginning. In other words - does [ping google.com -n 10] will ask dns for resolving google.com 10 times, or only once when it starts?Moffat
@guitar_freak, it depends on the implementation. However, I'm not sure that allowing for rapidly changing IP addresses for a given host name would be a particularly useful feature. The one I just looked up resolved once on program start, not before every single ICMP packet.Chamonix
How does ping know what 'normal' method to use? Afaik, ping implements resolv.c from the libc.Stinkwood
F
2

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

Freitas answered 27/10, 2020 at 8:55 Comment(0)
A
0

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.

Appendant answered 18/6, 2013 at 5:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.