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.

Share:
7,738

Related videos on Youtube

sanity
Author by

sanity

Updated on September 17, 2022

Comments

  • sanity
    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
      Username over 13 years
      Have you rebooted/restarted networking services after making the edit to your hosts file?
    • Sameer
      Sameer over 13 years
      Modification of hosts file doesn't require restart of network services.
    • David Mackintosh
      David Mackintosh over 13 years
      What does the hosts line in /etc/nsswitch.conf look like?
    • Nicola Boccardi
      Nicola Boccardi over 13 years
      where do you ping it, from the server itself or from another machine in the same lan?
    • sanity
      sanity over 13 years
      I've edited to answer these questions
    • Johan
      Johan almost 12 years
      As 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
    UncleAdam almost 7 years
    And what if they are already world readable, however you still can't ping localhost?