October 11, 2012

Techbits #24: “nslookup” works but “ping”, “telnet” etc. don’t?

This Techbit is for those souls that work on Solaris platform. It may be applicable on other Unix-based platforms as well but I've not verified it.

A friend of mine told me he has configured the name servers correctly in /etc/resolv.conf after which he could get "nslookup" working but not the other commands like "ping", "telnet" etc. Why?

The answer lies in that "nslookup" does DNS lookups using /etc/resolv.conf where as "ping", "telnet" etc. refer to /etc/nsswitch.conf to find out the mechanisms to use for name resolutions.  If DNS is not listed here, then /etc/resolv.conf is not going to be referred to. Therefore, make sure DNS is listed as a source for host resolution in /etc/nsswtich.conf.

Another command to do such verification is 'getent hosts' - this is like nslookup but pays attention to /etc/nsswitch.conf additionally.

Thus, to summarize which configuration file does each of the commands depend on:

nslookup - /etc/resolv.conf

ping - /etc/nsswtich.conf

telnet - /etc/nsswtich.conf

getent hosts - /etc/resolv.conf, /etc/nsswtich.conf

No comments: