Why is 'ping' unable to resolve a name when 'nslookup' works fine?
Solution 1:
I believe that nslookup opens a winsock connection on the DNS port and issues a query, whereas ping uses the DNS Client service. You could try and stop this service and see whether this makes a difference.
Some commands that will reinitialize various network states :
Reset WINSOCK entries to installation defaults : netsh winsock reset catalog
Reset TCP/IP stack to installation defaults : netsh int ip reset reset.log
Flush DNS resolver cache : ipconfig /flushdns
Renew DNS client registration and refresh DHCP leases : ipconfig /registerdns
Flush routing table : route /f
(this will remove all your gateways until you restart!)
Solution 2:
Try ping with hostname followed by a dot. So instead of ping wolfman
use ping wolfman.
That should get you resolving without having to do workarounds with hosts file, etc.
Solution 3:
Try adding .
to the DNS suffixes for that connection. I.e, go to:
- Ethernet Status
- Click Properties
- Internet Protocol Version 4
- Click Properties
- Click Advanced
- Append these DNS suffices (in order)
- Add
.
as a suffix.
The same steps are illustrated in the following screenshot:
This should make ping wolfman
work.
Explanation
nslookup wolfman
(name server lookup: wolfman) sends the hostname (wolfman
) to the DNS (domain name system) to obtain the corresponding IP address. This is the sole purpose of the nslookup
command. This works already, so we have verified that the DNS works and that wolfman
indeed corresponds to an IP address.
In contrast, ping wolfman
needs to do two things:
- Get the IP that the hostname (
wolfman
) corresponds to. - Send packets to the IP and listen for the response
On Windows (even recent versions such as Windows 10), the first step can easily fail. For the sake of backwards compatibility, Windows supports various methods of hostname resolution (hosts file, DNS, NetBIOS/WINS, LMHOST file).
Unfortunately, it seems that Windows' ping
command doesn't always attempt a DNS lookup. I don't know the specific conditions that triggers this behaviour.
Fortunately, we can force Windows to do a DNS lookup by using a FQDN (fully qualified domain name). In practice, we do this by suffixing a .
dot to the hostname: wolfman.
. Try ping wolfman.
and verify that it works.
The final step is to force Windows to append this dot itself. I've already shown how to do this in the beginning of this answer.