1826331 Members
3407 Online
109692 Solutions
New Discussion

nsswitch question

 
SOLVED
Go to solution
Lynn Hsu_2
Frequent Advisor

nsswitch question

Hi,
I have a Redhat webserver (HP DL360). When
doing "nslookup hostA" it said not found even
hostA is in /etc/hosts. The nsswitch.conf
defines to search files first:
hosts: files [NOTFOUND=continue] dns

The /etc/resovle.conf looks like this:
domain xyz.com
search xyz.com
nameserver 192.168.xx.yy

Why nslookup did not go to files first? what's wrong with nsswitch.conf file?

Lynn
9 REPLIES 9
Ivan Ferreira
Honored Contributor
Solution

Re: nsswitch question

The nslookup dig and host command will always try to use only DNS, they won't consult the /etc/hosts file. There is nothing wrong with your nsswitch.conf file.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
TwoProc
Honored Contributor

Re: nsswitch question

The command to resolve a name to an ip address - regardless of whether or not it is resolved in a dns server, or a host file, nis etc. is already in linux.

Run "gethostip" from the command line.

$> gethostip hostA

will return something like
hostA 192.168.xxx.xxx [8 digit hex number]

so, you'd want something like

$> gethostip hostA | cut -f 2 -d" "
192.168.xxx.xxx


We are the people our parents warned us about --Jimmy Buffett
TwoProc
Honored Contributor

Re: nsswitch question

This "may" end up looking like a repost.
Sorry if it does, it is taking about FIVE minutes to post right now, and I saw a change I wanted to make, and instead of a follow up - I'm trying to get it all in one post, in case it hasn't gone through yet.
--------Excuse if it is a double post--------

The command to resolve a name to an ip address - regardless of whether or not it is resolved in a dns server, or a host file, nis etc. is already in linux.

Run "gethostip" from the command line.

$> gethostip hostA

will return something like
hostA 192.168.xxx.xxx [8 digit hex number]

$> gethostip -d hostA

will return just the ip address

HTH
We are the people our parents warned us about --Jimmy Buffett
Lynn Hsu_2
Frequent Advisor

Re: nsswitch question

Thanks for the replies. So on Linux, is nsswitch.conf still useful? I think
it is for the name resolution search order.

Lynn
Steven E. Protter
Exalted Contributor

Re: nsswitch question

Shalom,

nsswitch.conf is critical. It decides how a system will resolve hostnames, how it will authenticate users, any number of things.

It is problably the most important configuration file after the network configuration.

As posted your nsswitch.conf file, which must be in the /etc directory should look in files first and then if not found continue to DNS.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Mark Fenton
Esteemed Contributor

Re: nsswitch question

The issue you are seeing is that nslookup doesn't use nsswitch.conf to determine where to find conversions from names to numbers, just resolv.conf.

applications like 'ping' use the standard system calls to do their resolution work.
TwoProc
Honored Contributor

Re: nsswitch question

That's right Lynn.
It is for name resolution search order (among other things).

U got it.
We are the people our parents warned us about --Jimmy Buffett
Lynn Hsu_2
Frequent Advisor

Re: nsswitch question

Thanks everyone.

Lynn
Lynn Hsu_2
Frequent Advisor

Re: nsswitch question

Got the answer.