h1

/etc/hosts on UNIX box

June 24, 2008

If you are having a problem resolving hosts on a UNIX box even when you do have a /etc/hosts file configured with the hosts which are not there on the DNS server, check to make sure that you have a /etc/nsswitch.conf file. I know that by default a few UNIX systems like HP-UX do have it as a sample file but are renamed to something else. A ls -al nsswitch* will get you a list of all files which start with nsswitch. Copy one of them to /etc/nsswitch.conf and edit the line which starts with hosts:

hosts:         files [NOTFOUND=continue UNAVAIL=continue TRYAGAIN=continue] dns

This will ensure that your hosts will be resolved first by looking into /etc/hosts and if not found there the DNS server will be used. This can be very useful in the even the DNS server crashes or is unavailable for any reason.

Leave a Comment