Table of Contents
Sudo unable to resolve host name
As you know, while installing a new operating system like Debian, Ubuntu, or any other Linux distribution, installers ask you to set the hostname. At that time, most users keep the default hostname.
But later, you have decided to change the hostname to some meaningful text, therefore you have modified the /etc/hostname to update the hostname.
And after the restart, you invoke the sudo command, which gives the error message sudo: unable to resolve host your-hostname: Name or service not known.
You will encounter the above error after making changes to /etc/hostname. And the resolution of this error is pretty simple.
1. First, SSH to the server then find your current machine hostname. In my case, it is cyberpanel, and to verify that, paste the below code on your terminal to find out:
cat /etc/hostname
root@cyberpanel:/home/bonben# cat /etc/hostname
cyberpanel
2. Once you know the machine-name or hostname from /etc/hostname, you can proceed to /etc/hosts to find the existence of your machine name in the respective file.
cat /etc/hosts
root@cyberpanel:/home/bonben# cat /etc/hosts
127.0.0.1 localhost vps01
# 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
ff02::3 ip6-allhosts
Now I found my problem. My hostname is an older one vps01, and the latest hostname or machine-name is cyberpanel.
3. So, simply modify the /etc/hosts with the correct hostname. Make sure to replace the machine with the actual hostname name. You can use any command line editor to modify /etc/hosts. In the following example, I’m using Nano to edit the file.
sudo nano /etc/hosts
root@cyberpanel:/home/bonben# cat /etc/hosts
127.0.0.1 localhost cyberpanel
# 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
ff02::3 ip6-allhosts
Once the file is modified save and close it. After that, try to execute the sudo command again and you will see that the error no longer bothers you.
Not a reader? Watch this related video tutorial: