Unable to resolve host [duplicate]

When I run sudo the terminal is stuck for a few seconds and then outputs an error message. My terminal looks like this:

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

What can I do to solve it?


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.


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

Mine looks like:

127.0.0.1       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.


Add your hostname to /etc/hosts like so:

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

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:

127.0.1.1   dave00-G31M-ES2

So it becomes:

127.0.1.1   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.


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:

127.0.0.1   localhost.localdomain localhost
127.0.1.1   ubuntu

I hope that will solve your issue :)

PS: Remember to reboot your computer!