System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Force nslookup use hosts file not the DNS

 
SOLVED
Go to solution
Qcheck
Super Advisor

Force nslookup use hosts file not the DNS

Hello smarts,

I am trying to force to use hosts file rather than DNS(resolv.conf), on RHEL 5.4. But doesn't work.

The order in /etc/host.conf has the following:
order hosts,bind

And the /etc/nsswitch.conf has the following:
[root]# grep hosts /etc/nsswitch.conf
#hosts: db files nisplus nis dns
#hosts: files dns
hosts: files
[root]#

[root]# nslookup
Server:
Address:

** server can't find : NXDOMAIN

[root]

Any ideas gurus?
3 REPLIES
Matti_Kurkela
Honored Contributor
Solution

Re: Force nslookup use hosts file not the DNS

The nslookup command is originally a DNS server testing tool. The RHEL default version of nslookup will always try to contact a DNS server, because that's what it's programmed to do.

If you want to test the name resolver libraries (which use whatever is configured to /etc/nsswitch.conf), you'll need to use another tool: the "getent" command.

In your case, the command syntax is "getent hosts "

Note: the "hosts" in the getent command line does not refer to /etc/hosts directly, but to the "hosts:" line in /etc/nsswitch.conf.

The getent command can be used to test other lookup mechanisms specified in /etc/nsswitch.conf too: for example, if you're setting up LDAP and need to verify that usernames are being looked up from your chosen source, you might run a command like "getent passwd ".

MK
MK
Qcheck
Super Advisor

Re: Force nslookup use hosts file not the DNS

Mk, Thank you for the response. But getent doesn't work in my situation as one of the application is looking for the ip address which s specified in hosts file, as the DNS server has the new IP, which we haven't changed yet due to the downtime issue. Of course eventually we will change and I know it works then. Meanwhile, I thought nslookup might work looking at the hosts file rather than the resolv.conf file. But looks like not.

Thank you for the information, really very helpful.
Tim Nelson
Honored Contributor

Re: Force nslookup use hosts file not the DNS

how about a simple ping ?

as Matti mentioned, use a different tool.