Getting "unknown host" on hostname despite adding it to /etc/hosts
7,738
Check permissions on /etc/hosts and /etc/nsswitch.conf files. They should be world-readable.
Related videos on Youtube
Author by
sanity
Updated on September 17, 2022Comments
-
sanity almost 2 years
I have an Ubuntu server called crow:
$ hostname crow
But when I try to ping it (from itself), I get unknown host:
$ ping crow ping: unknown host crow
This is despite explicitly adding crow to /etc/hosts:
$ sudo cat /etc/hosts 127.0.0.1 localhost crow
What am I doing wrong?
Additional info in response to comments:
The hosts line of /etc/nsswitch.conf looks like this:
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
-
Username over 13 yearsHave you rebooted/restarted networking services after making the edit to your
hosts
file? -
Sameer over 13 yearsModification of hosts file doesn't require restart of network services.
-
David Mackintosh over 13 yearsWhat does the hosts line in /etc/nsswitch.conf look like?
-
Nicola Boccardi over 13 yearswhere do you ping it, from the server itself or from another machine in the same lan?
-
sanity over 13 yearsI've edited to answer these questions
-
Johan almost 12 yearsAs reference I once had this problem since I by mistake "lost" the s in hosts (in nsswitch.conf). So a faulty nsswitch.conf can cause this problem as well...
-
-
UncleAdam almost 7 yearsAnd what if they are already world readable, however you still can't ping localhost?