Error running sudo (sudo: unable to resolve host [name]: Connection timed out)

Whenever I run a sudo command, I get an error message.

jay@ignumtop:~$ sudo true
sudo: unable to resolve host ignumtop: Connection timed out

I'm not sure how this is really affecting my computer or anything, but if it's an issue that'll lead to my computer bonking itself, I'd like to know what I can do about it. Thanks.


Solution 1:

This is most likely a case of a mismatch between records in /etc/hosts and your hostname in /etc/hostname.

Firstly, let's start with /etc/hostname and get your actual hostname with the command cat /etc/hostname which will output the hostname of your system:

foobarbaz

(foobarbaz is an example of the output).

Next, let's check your /etc/hosts file. You should see something like this from cat /etc/hosts:

127.0.0.1   localhost
127.0.1.1   foobar

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

In this example, you can see 'foobarbaz', the hostname I have on my system, is not in /etc/hosts. So let's add it, edit the line for 127.0.1.1 to include your hostname on it sudo nano /etc/hosts will open the nano text editor on the command line so you can edit and save the file - note you'll have to wait for the 'timed out' problem to resolve itself again):

127.0.1.1   foobar foobarbaz

Save the file, then try your sudo commands again. You should no longer see this error.