17

Every time I try to use sudo I get this:

sudo: unable to resolve host ubuntu-server

My /etc/hosts file:

127.0.0.1       localhost
127.0.1.1       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:

ubuntu-server

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
2

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

  • This is the default configuration with Vagrant precise32. It uses 127.0.1.1 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
  • 7
    -1 This answer is incorrect. bugs.launchpad.net/ubuntu/+source/rescue/+bug/19553/comments/9 kind of explains this. 127.0.1.1 is a common placeholder for when you don't want to, or cannot, use 127.0.0.1. They both ultimately resolve to the local loopback interface (as does anything in the 127.0.0.0/8 reserved netblock). – tripleee Jul 25 '14 at 4:21
1

This may mean your DNS lookups are broken.

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

127.0.0.1       localhost
127.0.1.1       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 8.8.8.8
nameserver 8.8.4.4
nameserver 2001:4860:4860::8888
nameserver 2001:4860:4860::8844

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