Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Please post the contents of /etc/hostname and /etc/hosts. – arrange Aug 31 '11 at 20:24
I recommend against closing this question as too localized. There are many users who may mistakenly think they've put one name in their hosts file but put in a different name instead, especially since on many networks, computers are similarly named. This question (and answer) would show up when someone searches with that problem, and the answer would prompt them to check for such discrepancies, even though the exact misspelling would be different. – Eliah Kagan Aug 18 '12 at 11:09
make sure your hostname same with hosts. e.g. the hostname is ubuntu-pc and hosts is ubuntu-pc must be same. – Muhammad Sholihin Apr 1 '13 at 8:17

18 Answers 18

up vote 384 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:    localhost.localdomain localhost    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. – Yashvit May 5 '13 at 15:22
Thanks this helped.! – Rahul Jun 15 '15 at 16:44
Note: since you can't sudo to begin with, it is difficult to edit those files. My solution was I was somehow able to sudo visudo and change #%admin ALL=(ALL) ALL to %admin ALL=NOPASSWD: ALL , then reboot, and sudo su -, edit those files, set/correct hostname, reboot again, and everything worked. – Ian M Jul 17 at 20:19

Edit /etc/hosts and append your new hostname to the line (or create a new line if you prefer that).

Mine looks like:       localhost localhost.localdomain 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
How can he edit the /etc/hosts file if he can't sudo? Unless he created a rood account with a password (bad idea) – Dennis Mar 29 '15 at 22:31
@Dennis You can still execute sudo even if that message is displayed. IIRC you still have to enter your password at each invocation though. If this does not work, you can reboot into the recovery console and apply the changes. A root account with password is discouraged. – Lekensteyn Mar 29 '15 at 23:31

Note, this is an answer to this question which has been merged with this one.

Your hostname (dave00-G31M-ES2L) is not represented in /etc/hosts. Add an L to this line:   dave00-G31M-ES2

So it becomes:   dave00-G31M-ES2L

In order to accomplish this, open a console (press Ctrl+Alt+T) and type:

sudo gedit /etc/hosts

Add the letter L as mentioned, save and exit.

share|improve this answer
Remember! Use sudoedit (or sudo -e). To specify preferred editor, use the EDITOR environment variable (eg. export EDITOR=vim) as it creates an offline copy for editing and then cleanly overwrites after editing. – Jan Sep 26 '14 at 13:54
And there is another one here who suggest sudo when there is no longer sudo. sudo doesn't work, sir. sudo: unable to resolve host ... – Green Jul 12 at 20:18
@Green: No sudo? The error message you mention comes from the sudo command. Perhaps you meant something different? – Thor Jul 14 at 13:49
@Green sudo works just fine. It just can't store any state (i.e. as Lekensteyn said elsewhere you have to enter your password every time). – Wlerin 6 hours ago

I had this issue when I was using ubuntu on a VPS. I solved it editing /etc/hosts file.

run this command:

sudo nano /etc/hosts

and then add:   localhost.localdomain localhost   ubuntu

I hope that will solve your issue :)

PS: Remember to reboot your computer!

share|improve this answer
Also, see if your device name (printed on the Terminal title bar after the @ sign) matches the name on the second line of the hosts file ("ubuntu" in Luca's example). The first line may also be just "localhost". – Waldir Leoncio Oct 26 '13 at 14:33
Remember! Use sudoedit (or sudo -e). To specify preferred editor, use the EDITOR environment variable (eg. export EDITOR=vim) as it creates an offline copy for editing and then cleanly overwrites after editing. – Jan Sep 26 '14 at 13:55
thanks a lot for this answer – kapil Dec 26 '15 at 14:42

In AWS, go to your vpc and turn on "DNS Hostnames".

share|improve this answer
Welcome to askubuntu! Can you expand a bit on this? It's not abundantly clear what you mean (at least to me).. – Elder Geek Jan 15 '15 at 13:56
This may not be relevant to the question, but it greatly helped me. Thank you! – clayzermk1 Apr 10 '15 at 17:35
This was the answer that helped me. Amazon AWS changed since the last time I looked at it. VPCs have DNS options, and they need to be turned on before any DNS resolution will work. – Chris Moore Jul 1 '15 at 1:16
the Enable DNS Hostnames option can be found (for example) in the right-click menu of the vpc entry – Matteo Scotuzzi Jan 3 at 17:32
There is no DNS Hostnames – Green Jul 12 at 20:11

I was having the same issue even though the hostname in my /etc/hostname file and /etc/hosts file matched.

My hostname was "staging_1". It turns out that you can't have an underscore in your hostname, which is why I was getting this error. Changing the underscore to a hyphen fixed my problem.

share|improve this answer

In my case it was the problem, I changed the hostname to man because I wanted to know if there are some parameters you can use on hostname. Instead it changed my hostname to man and I always got the same message like you

sudo: unable to resolve host (none)

after changing the hostname back to `localhost everything worked fine again

hostname localhost
share|improve this answer

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


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

OP wrote:

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

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

share|improve this answer

Add your hostname to /etc/hosts like so:

echo $(hostname -I | cut -d\  -f1) $(hostname) | sudo tee -a /etc/hosts
share|improve this answer

I encountered this same error message. I think this discussion thread at AWS Developer Forums is a better solution:

"Go the the VPC management console, select the VPC, click on Actions, select Edit DNS Hostnames and select Yes."

share|improve this answer

Some terminal emulators will not update prompt with the correct hostname until you close and restart the emulator (lxterminal, I'm talking to you).

I spent 30min fighting with this error after editing my hostname and hosts files and running sudo service hostname restart until I ran sudo hostname and saw that the hostname was the new value, even though the prompt was showning the old value.

share|improve this answer

you might be getting an error if your hosts or hostname file contain illegal characters. Only these symbols are permitted: a-z, A-Z, 0-9

share|improve this answer

I had the same problem. I solved it by editing the /etc/hosts and /etc/hostname files... on the /etc/hosts file, just edit the top part as shown below.

#vi /etc/hosts   localhost   localhost  myhostname

#vi /etc/hostname
share|improve this answer localhost myhostname or myhostname? – Mostafa Ahangarha Mar 26 at 18:43
How can you edit /etc/hosts without sudo. sudo doesn't work sudo: unable to resolve host ... – Green Jul 12 at 20:02

First you have to edit the hostname in /etc/hostname file.

Then you have to edit the hostname in /etc/hosts file.

If you type different hostnames in /etc/hostname and /etc/hosts then you will get the error like unable to resolve host.

So you can enter same hostname into the /etc/hostname and /etc/hosts.

After edited, just start the services for hostname sudo service hostname start, then if you check hostname command it will give the new name.

share|improve this answer
How can you edit /etc/hostname when you do not have sudo any longer? sudo: unable to resolve host .... Downvote – Green Jul 12 at 20:15

First go to your system file >then etc >then locate the file called hostname. Open it and you'll find a name. It's your machine's name.

Then open the terminal and type >> sudo gedit /etc/hosts. Text editor should open up. There you will find a name in the second line. Replace it with the hostname you already found and save it. Done.

P.S.- Don't edit the numbers in the second line. Edit only the text.

share|improve this answer
And there is another one here who suggest sudo when there is no longer sudo. sudo doesn't work, sir. sudo: unable to resolve host ... – Green Jul 12 at 20:06

This happens when you messes up with your hosts and hostname. No worries I myself had this problem and solved it. Just follow the steps below.

First check your hosts. For doing so key the following in your terminal:

" cat /etc/hosts " - You should get the following.

""Forget the IPv6 parts and just focus on first 2 lines"" They should look the way I have shown: If not you have to edit it and for doing so follow the steps given1 below:

Type : sudo gedit /etc/hostname /etc/hosts (in the terminal)
A test editor would open use it to open hosts tab and under remember to edit localhost.localdomain localhost
and second one -to your pc name(Whichever you have kept) . edit the file under the hosts tab and save it.
You are then good to go.

No need to touch IPv6 settngs.

Please ! Check the link below more explanation about editing /etc/hosts: OF How your hosts file should look

Hope this helps. I searched this over Internet when I myself stumbled over THIS!!! Now it's solved.

share|improve this answer
What are you talking about? Can't you read the question? sudo command DOESN'T WORK. sudo has gone, there is no longer sudo. Every sudo call returns sudo: unable to resolve host .... How can you suggest solution that uses sudo? Down vote – Green Jul 12 at 19:59

Just change the the host name like your PC in system settings --> details. Change the host name like the name shown in settings.       localhost.localdomain localhost   host name
# 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
share|improve this answer

Your Answer


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.