Operating System - HP-UX
1828317 Members
4919 Online
109976 Solutions
New Discussion

Re: DNS resolver and etc/hosts file

 
SOLVED
Go to solution
jason thompson_1
Frequent Advisor

DNS resolver and etc/hosts file

Once the DNS resolver is configured the server ignores the etc/hosts file, is this normal? We have hosts in the host file that the DNS resolver is unaware of.
What's that smell?
6 REPLIES 6
Craig Rants
Honored Contributor

Re: DNS resolver and etc/hosts file

Make sure your /etc/nsswitch.conf file entry for hosts looks like this:

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

GL,
C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Jeff Schussele
Honored Contributor

Re: DNS resolver and etc/hosts file

Hi jason,

Make sure that in you /etc/nsswitch.conf file the hosts line is as follows

hosts: dns [NOTFOUND=continue] files

Or you can switch the order of dns/files if you want - the first will be searched first.
The key is to have BOTH in there & to tell it to continue if it's not in the first searched.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
steven Burgess_2
Honored Contributor
Solution

Re: DNS resolver and etc/hosts file

Hi

A little expansion on both replies

A little expansion on Patrick's reply

The entry in nsswitch is related to as the 'fall back mechanism'

When you send a query to the lookup resource always yields one of 4 results

SUCCESS - source found requested entry
UNAVAIL - Source is not configured
NOTFOUND - source responded "no such entry"
TRYAGAIN - server not responding

When the resolver receives one of these responses you can configure it to react in 2 ways

continue - Try the next source in the list
return - quit searching

Lets say we have the following in /etc/nsswitch

hosts: dns files

The above says that the resolver should try DNS first - SUCCESS = return else use the /etc/hosts files

As per Patrick's example - he is more explicitly defining the fallback mechanism

hosts : files [NOTFOUND=continue] dns

With the above entry , if the host is not found using /etc/hosts then the resolver will consult dns

If these actions are not specified the resolver uses the following defaults

SUCCESS=return
NOTFOUND=return
UNAVAIL=continue
TRYAGIN=continue

Therefore the UNAVAIL and TRYAGAIN lines ensure that the other specified resource is used

Hope this helps

Steve
take your time and think things through
jason thompson_1
Frequent Advisor

Re: DNS resolver and etc/hosts file

Perhaps that is the problem as there is not a etc/nsswitch.conf file.
What's that smell?
Sanjay_6
Honored Contributor

Re: DNS resolver and etc/hosts file

Hi Jason,

The resolver works in the order specified in the /etc/nsswitch.conf file. To check your /etc/hosts file first and then DNS, have this entry in /etc/nsswitch.conf file,

hosts : files [NOTFOUND=continue] dns

Hope this helps.

Regds
MANOJ SRIVASTAVA
Honored Contributor

Re: DNS resolver and etc/hosts file

Jason

Also you need to specify the DNS server in /etc/resolv.conf . The best way is to do a nslookup hostname and see how tghe same is resolved .

/etc/hosts should be like a backup for the DNS entreies ie in case the DNS server breaks down then the system look as at the /etc/hosts for resolving the name and addresses instead of looking for the DNS server only.


Manoj Srivastava