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

/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


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?



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.



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


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.