Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have this issue on AWS on some servers. Whenever I run sudo the terminal is stuck doing seemingly nothing, until it finally spits out this error message. My terminal looks like this:

ubuntu@(none):~$ sudo true
sudo: unable to resolve host (none)

What can I do to solve it?


Update: Solved! It was all in /etc/hostname. On two of our sick servers it looked like this:

ubuntu@(none):~$ cat /etc/hostname
linux-web-n ip-10-128-##-##

While on a server without this issue we had:

ubuntu@ip-10-128-##-###:~$ cat /etc/hostname
ip-10-128-##-###

Removed the linux-web-n portion, rebooted and everything was fine. Thanks. :)

share|improve this question
Please post the contents of /etc/hostname and /etc/hosts. – arrange Aug 31 '11 at 20:24

3 Answers

up vote 20 down vote accepted

Two things to check (assuming your machine is called my-machine, you can change this as appropriate):

  1. That the /etc/hostname file contains just the name of the machine.

  2. That /etc/hosts has an entry for localhost. It should have something like:

     127.0.0.1    localhost.localdomain localhost
     127.0.1.1    my-machine
    

If either of these files aren't correct (since you can't sudo), you may have to reboot the machine into recovery mode and make the modifications, then reboot to your usual environment.

share|improve this answer
The hostname will not change until you reboot. If you wish to change it without rebooting the machine then follow the above steps and after that run:- "sudo hostname my-machine" to see if this has worked run "sudo hostname" It will show your machine's host name. This method maybe used as a temporary method to change hostname also. after a restart, the value from the /etc/hostname file is used. – Yash May 5 at 15:22

Edit /etc/hosts and add your new host name to the 127.0.0.1 line.

Mine looks like:

127.0.0.1       localhost
192.168.2.2     penguin

# 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

Replace "penguin" in the above example by your new hostname as stated in the /etc/hostname file.

share|improve this answer
Thanks, it works! – Harris6310 Apr 7 '12 at 13:56

Sorry I can't help you much but, since it says "can't resolve host" try running:

hostname

And see if the output is the hostname of the machine. If not, the problem is the host configuration, not sudo.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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