precedence of /etc/hosts file

I have put an entry in my hosts file, like:

ip_address hostname.fqdn hostname

but if I do nslookup it still goes to my DNS server looking for the name - and fail.

How do I get the server to look /etc/hosts file first and DNS second?

Thanks.

On Wed February 4 2009 08:36 pm, henders254 wrote:

>
> I have put an entry in my hosts file, like:
>
> ip_address hostname.fqdn hostname
>
> but if I do nslookup it still goes to my DNS server looking for the
> name - and fail.
>
> How do I get the server to look /etc/hosts file first and DNS second?
>
> Thanks.
>
>
henders254;

Edit the “hosts:” entry of
/etc/nsswitch.conf
to read:


hosts:          dns files


P. V.
“We’re all in this together, I’m pulling for you.” Red Green

in the /etc/nsswitch.conf file I changed

hosts: files mdns4_minimal [NOTFOUND=return] dns

to

hosts: dns files

restarted network daemon but it is still not working.

Hi
It needs to be the other way around, files dns


Cheers Malcolm °¿° (Linux Counter #276890)
openSUSE 11.1 x86 Kernel 2.6.27.7-9-default
up 1 day 10:14, 2 users, load average: 0.15, 0.18, 0.14
GPU GeForce 6600 TE/6200 TE - Driver Version: 180.22

On Wed February 4 2009 09:21 pm, Malcolm wrote:

>

> Hi
> It needs to be the other way around, files dns
>

Yup! When I wrote the reply I was (not)thinking the OP wanted to use dns
rather than files.

An example Name Service Switch config file. This file should be

sorted with the most-used services at the beginning.

The entry ‘[NOTFOUND=return]’ means that the search for an

entry should stop if the search in the previous entry turned

up nothing. Note that if the search failed due to some other reason

(like no NIS server responding) then the search continues with the

next entry.


P. V.
“We’re all in this together, I’m pulling for you.” Red Green

I have setup “hosts: files dns” and deleted the nameservers in /etc/resolv.conf file and restarted network daemon. I did nslookup for the hostname that is in my /etc/hosts file and nslookup times out.

On Wed February 4 2009 08:36 pm, henders254 wrote:

>
> I have put an entry in my hosts file, like:
>
> ip_address hostname.fqdn hostname
>
> but if I do nslookup it still goes to my DNS server looking for the
> name - and fail.
>
> How do I get the server to look /etc/hosts file first and DNS second?
>
> Thanks.
>
>
henders254;
After thinking about this, it looks like “nslookup” or “host” will only query
the name server and never the files. see: man nslookup and/or man host

P. V.
“We’re all in this together, I’m pulling for you.” Red Green

Yes, after all, nslookup stands for Name Service Lookup. :slight_smile:

henders254 schrieb:
> I have put an entry in my hosts file, like:
>
> ip_address hostname.fqdn hostname
>
> but if I do nslookup it still goes to my DNS server looking for the
> name - and fail.
>
> How do I get the server to look /etc/hosts file first and DNS second?

By not using nslookup. :slight_smile:

nslookup only looks in DNS. That’s what it was made for.

If you want to see whether your entry in /etc/hosts works,
use some program that actually tries to access the machine,
preferably one that actually prints the IP address it tries
to contact, such as ping, ssh, or telnet.

HTH
T.