Nslookup resolves address but ping is unable to resolve hostname on Unix server

I came across this issue on my newly built Solaris 10 server. I was able to ping a remote machine by Ip address, but not by its hostname. This indicated that I had the correct route and gateway. Using nslookup and dig I verified that the DNS servers were resolving the hostname to IP address. I confirmed that the file /etc/resolv.conf had the correct syntax for search domain-name.com.

Here is what my /etc/resolv.conf looks like, the two DNS servers are defined correctly as it the search domain.
domain andrewlin.com
search andrewlin.com

The gateway was defined in /etc/defaultrouter.
It seems that ping did not know how to resolve an address. I was also not able to surf the internet with the Firefox browser in the Sun Java Desktop System for Soalris. All symptoms indicated that the nsswitch.conf did not have the correct environment defined. The /etc/nsswitch.conf file defines which services are to used to retrieve information such as hostnames, password files, and group files. So in this case for the command ping and firefox which wants to resolve and address, it will check the nsswitch.conf file to see what services to use.

Below are the lines I changed in /etc/nsswitch.conf, by adding dns to the end of each lines.
hosts: files dns
ipnodes: files dns

I am now able to ping and surf the internet without any issues.

1 comment for “Nslookup resolves address but ping is unable to resolve hostname on Unix server

  1. Sean Brady
    December 5, 2010 at 8:31 pm

    I experience this same issue every time I setup a solaris virtual machine. Easy fix!

Comments are closed.