Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My hosts file is being ignored, apparently.

It contains: localhost.localdomain localhost nowhere

If I ping localhost or 'nowhere', I get an 'unknown host' error. If I ping, ping succeeds, but it reports the internet ip address (from an outside name server) for

The server is running ubuntu hardy. Is there a way disable (and reenable) the /etc/hosts file?

share|improve this question
up vote 8 down vote accepted

I found the problem.

The /etc/hosts file had overly restrictive permissions -rw------ (I believe that is 600 octal). Changing that to mode 644 fixed the problem.

My tests with ping were done with ordinary priv, and the hosts file was unreadable. My original problem was getting postgresql to startup properly; it starts with root privilege, but apparently sheds priv before starting its child processes for autovacuum and such, so by the time it needed a domain resolved, it could not read the hosts file.

Thanks to everybody who replied. It has been enlightening.

share|improve this answer
You just saved me a heap of time. Thank you :) – Gerry Feb 19 '12 at 16:18

Check /etc/nsswitch.conf

You should have a line like:

hosts: files dns

if the "files" part is missing, /etc/hosts won't be checked.

share|improve this answer

the hosts file is strange sometimes on some distrib, try put all localhost alias in the same line

like this : localhost.localdomain localhost nowhere
share|improve this answer
You just saved my life man!!! Brilliant! Wasted two hours till i saw this – In God I Trust Sep 6 '12 at 18:12

Not sure of the specifics of ubuntu, but it seems like your local resolver isn't configured properly. You should try man resolv.conf or man nslookup to see how to configure it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.