Every time I try to use sudo I get this:

sudo: unable to resolve host ubuntu-server

My /etc/hosts file:       localhost       ubuntu-server

# The following lines are desirable for IPv6 capable hosts

::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
FF02::2 ip6-allrouters

/etc/hostname has:


I think there is some other setting that causes the unable to resole host error, but I cannot find these.

  • Compare content of your /etc/hostname with the second line of /etc/hosts. Are there any special characters not printed out?
    – user279434
    May 8 '14 at 14:13

This may mean your DNS lookups are broken.

Your /etc/hosts file looks fine. You want it too look like this:       localhost       ubuntu-server

But there are several legitimate variants.

Make sure you have a matching hostname in /etc/hostname .

Check /etc/resolv.conf to see if you have working name servers defined.

See if you can resolve any hostnames. Does nslookup google.com work ? If not, your DNS lookup is failing, either due to configuration or a network or firewall problem (possibly at a point beyond what you have control of with your server).

In my experience, sudo will eventually ask you for you password, and grant you elevated privileges, after domain lookup times out.

Try manually adding the correct DNS name servers to /etc/resolv.conf.

In a pinch, you can use public servers. Here's what the file looks like using Google DNS servers:

/etc# cat resolv.conf
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844

Edit the /etc/hosts, you have a typo is not loopback, change it to, save and reboot.

  • This is the default configuration with Vagrant precise32. It uses on that line... are you sure this is wrong? It was working fine until I tried changing my hostname away from the default.
    – mpen
    Mar 1 '14 at 2:42
  • 8
    -1 This answer is incorrect. bugs.launchpad.net/ubuntu/+source/rescue/+bug/19553/comments/9 kind of explains this. is a common placeholder for when you don't want to, or cannot, use They both ultimately resolve to the local loopback interface (as does anything in the reserved netblock).
    – tripleee
    Jul 25 '14 at 4:21

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