Any command I put into the LXTerminal of my raspberry pi, it says Sudo unable to resolve host (none) I can’t download anything, even Sudo apt-get update How do I fix this"?
2 Answers
Have a look at nano /etc/hostname
There you should find one line with the name of your machine.
Then have a look at nano /etc/hosts
There you should find two lines. One localhost and one with your hostname:
127.0.0.1 localhost 127.0.1.1 your_host_name
The problem manifests itself when a command is issued under sudo
. For example:
$ sudo apt autoremove
sudo: unable to resolve host the_name: Name or service not known
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
In other words, the command executes as it should, but the annoying error message appears after each use of sudo
:
sudo: unable to resolve host <XXXX>: Name or service not known
I don't know what causes this issue, but here's something that may fix it:
- get your hostname from /etc/hostname, or:
$ cat /etc/hostname
the_name
# --OR--
$ hostname
the_name
- check your
/etc/hosts
file; you may see something like this:
cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 raspberrypi
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
- There should be two entries for the loopback address (127.0.0.1). The problem is caused when one of the loopback addresses does not have the proper hostname assigned, or has no name assigned, or there is only one line for this address.
Remedy this by opening the /etc/hosts
file in your editor, and changing the hostname for second entry/line 127.0.0.1 to the same name that is in the /etc/hostname
file. Using this case as an example, change the second line:
FROM:
127.0.1.1 raspberrypi
TO:
127.0.1.1 the_name
You can double-check this after your edit - you should see this:
cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 the_name
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
And that should take care of it.