Sudo: unable to resolve host

When I run this command on Debian 8.1

# sudo apt-get update && sudo apt-get upgrade -y && sudo apt-get dist-upgrade -y && sudo apt-get autoremove --purge -y && sudo apt-get autoclean -y

I got this error:

How to solve this? My server hostname has proper DNS IP pointed to it.

Hello @RoldanLT

could you please provide me output of following commands:

cat /etc/hostname


cat /etc/hosts

cat /etc/hostname 

cat /etc/hosts	localhost	debian

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

FYI, I just censor My original hostname, and replace with this dummy

Hello @RoldanLT

Please replace debian


and try

apt-get update

Hope above will resolve your sudo: unable to resolve host problem

I used to get this same “Unable to resolve host” error a lot, when setting up debian servers (not so much anymore). I used to get this error so often, I made a development note about it, in my Apple Notes app. When I opened that note, I was reminded that there used to be a script you needed to run, after changing:


…which was:

/etc/init.d/ start

However, I believe that script has now been replaced with the following command:

sudo service hostname start

…which should allow you to test by issuing the following command:


…which should output your newly assigned hostname. I suggest though, you may need to test the output of the last command, after restarting your server.

But I got this:

sudo service hostname restart

Failed to restart hostname.service: Unit hostname.service is masked.

Fixed now with @Prabuddha solution :). Thanks!

Hello @RoldanLT

I hope your query is resolved. I am closing this support topic for now.

Feel free to create a new support topic if you have any queries further. :slight_smile: