Sudo: unable to resolve host myhost.name.com

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: https://gist.githubusercontent.com/RoldanLT/ee00d64154727e31c495/raw/9f57bec5f8da1459b1bd0728a687fa7d727c6356/gistfile1.txt

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

and

cat /etc/hosts

cat /etc/hostname

myhost.name.com 

cat /etc/hosts

127.0.0.1	localhost
127.0.1.1	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 myhost.name.com.

Hello @RoldanLT

Please replace

127.0.1.1 debian

with

127.0.1.1 myhost.name.com

and try

apt-get update

Hope above will resolve your sudo: unable to resolve host myhost.name.com 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:

/etc/hostname

…which was:

/etc/init.d/hostname.sh 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:

hostname

…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: