Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Networking
cancel
Showing results for 
Search instead for 
Did you mean: 

nslookup not picking up hosts file entry if ipaddress not alive

SOLVED
Go to solution
Alan Casey
Trusted Contributor

nslookup not picking up hosts file entry if ipaddress not alive

I am trying to resolve a host to a dummy ipaddress, but if I enter this dummy ip n the hosts file, nslookup will continue and resolve it by DNS even though its set to look at hosts first!

# more /etc/nsswitch.conf
passwd: files
group: files
hosts: files [NOTFOUND=continue] dns
networks: files
protocols: files
rpc: files
publickey: files
netgroup: files
automount: files
aliases: files
services: files

# more /etc/hosts
10.195.101.321 ieswthsrv102.axa-ie.intraxa ieswthsrv102

# nslookup ieswthsrv102
Using /etc/hosts on: iexiwqc

looking up FILES
Trying DNS
Name: ieswthsrv102.axa-ie.intraxa
Address: 10.195.99.68


HOWEVER If I change the ipaddress in the hosts file to one that is alive, although not the correct one, it resolves from the hosts file:
# more /etc/hosts
10.195.101.64 ieswthsrv102.axa-ie.intraxa ieswthsrv102

# nslookup ieswthsrv102
Using /etc/hosts on: iexiwqc

looking up FILES
Name: ieswthsrv102.axa-ie.intraxa
Address: 10.195.101.64
Aliases: ieswthsrv102


Any ideas why this is happening?
4 REPLIES
Alan Casey
Trusted Contributor

Re: nslookup not picking up hosts file entry if ipaddress not alive

ok I have already found the solution
I updated nsswitch.conf to show:

hosts: files [NOTFOUND=continue UNAVAIL=continue FOUND=return] dns

and this will resolve in the way I want it.
Should this not be default?
I dont understand why you would want to resolve to dns if its in the hosts file
Alan Casey
Trusted Contributor

Re: nslookup not picking up hosts file entry if ipaddress not alive

Well it looks like I spoke to soon, the host is now, with the nsswitch conf as above not using the hosts file for this lookup.
I rebooted and its still doing the wrong thing
hostfile:
10.195.101.321 ieswthsrv102.axa-ie.intraxa ieswthsrv102

# nslookup ieswthsrv102
Using /etc/hosts on: iexiwqc

looking up FILES
Trying DNS
Name: ieswthsrv102.axa-ie.intraxa
Address: 10.195.99.68


Any ideas whats wrong here?
TTr
Honored Contributor
Solution

Re: nslookup not picking up hosts file entry if ipaddress not alive

Maybe nslookup is too smart and when it sees the "321" in the IP (which is an invalid octant number) it refuses to give you that IP and continues on to DNS.

Check with a nonexistent host, nonexistent IP but valid IP number.
Alan Casey
Trusted Contributor

Re: nslookup not picking up hosts file entry if ipaddress not alive

thank you Ttr, I hadnt spotted that but it seems to have sorted it.
Mystery solved