Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a problem with sudo. Every time when I trying to use sudo I got this problem:

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 gives:

ubuntu-server

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

share|improve this question
    
Compare content of your /etc/hostname with the second line of /etc/hosts. Are there any special characters not printed out? –  Thomas May 8 at 14:13

2 Answers 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.

share|improve this answer
    
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. –  Mark Mar 1 at 2:42
1  
-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 at 4:21

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
share|improve this answer

protected by Community Jul 23 at 21:47

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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