Operating System - Linux
1752627 Members
5259 Online
108788 Solutions
New Discussion

Re: /etc/hosts get ignored on redhat 6

 
Hanry Zhou
Super Advisor

/etc/hosts get ignored on redhat 6

 

I tried the following in /etc/nsswitch.conf:

hosts:  files [NOTFOUND=continue] dns

or

hosts: files dns

Also, in /etc/host.conf

order files,bind

 

Whatever I do, /etc/hosts still could not get checked, as if get ignored. Would you please let me know why?

 

Thanks!

none
2 REPLIES 2
Jim_Walls
Occasional Advisor

Re: /etc/hosts get ignored on redhat 6

How are you checking?

 

If you use either of nslookup or hosts then you will get unexpected results.  These commands ignore /etc/hosts and go directly to the DNS for name resolution.  The only way I know of checking the order in which names are resolved is to invoke something like ping, telnet or ssh, and see what address the hostname resolves to.

 

 

Matti_Kurkela
Honored Contributor

Re: /etc/hosts get ignored on redhat 6

In Linux, the "getent" command can be used to test hostname resolution using the order specified in /etc/nsswitch.conf.

 

For example:

# getent hosts localhost
# getent hosts localhost4 # getent hosts 127.0.0.1

 

The "getent" command can be used to test other name resolution services too: for example, "getent passwd username" would find the user's /etc/passwd information from any configured source (i.e. /etc/passwd, NIS and/or LDAP).

 

Also, make sure you haven't accidentally changed the permissions of the /etc directory or of the configuration files /etc/nsswitch.conf, /etc/resolv.conf and /etc/hosts: these need to be readable by all users, but writeable by root only.

MK