How to Resolve “SUDO UNABLE TO RESOLVE HOST” Error
Some users encounter an error “sudo unable to resolve host”. Usually, this error appears after changing the computer name. This is a simple problem that can be solved simply.
In this article, we’ll look at why this error occurs, what it means, and how to solve it with Ubuntu.
SUDO: UNABLE TO RESOLVE HOST
The message “unable to resolve host hostname” means that the utility cannot determine the IP address of host “hostname“. It would seem that sudo is a local command for increasing privileges in the system and it does not need to define IP hosts. But this is not so, sudo can be used by remote users, for example, connected via SSH.
And now we are interested in what for each query the utility needs to determine which host is used on this computer. Briefly, the main idea of developers is that one universal file / etc / sudoers will be used on multiple computers and each computer needs to determine what rules are intended for it. Thus, the host variable in sudoers only affects local rules.
And now back to our error. As I said, it means that the utility cannot resolve the hostname. For a site domain, this would mean that there is no such record in the DNS. But since this is the name of our local computer, it is obvious that it is not in the global network.
How to fix the error.
The solution is in the /ETC/HOSTS
To fix the error, we can add this DNS record locally to the / etc / hosts file. Since sudo does not work for you, and this file can only be edited from the superuser, this simple task becomes more complicated. First, we look at our current hostname:
hostname
Next, if you have a root password, you can log in to it with su:
su –
And then add this line to / etc / hosts:
vi /etc/hosts
127.0.0.1 hostname
You should replace the words hostname with the “hostname” that you received with the hostname command. After that, you need to restart the computer or just restart the network:
sudo systemctl restart networking
It is also advisable to make sure that the use of the / hosts file is enabled in the Domain Name System Service. Open /etc/nsswitch.conf and look for the files in the host’s line. It should be in the first place. If not, move it to the first place.
If you do not have a password for root, you need to boot from the LiveCD drive, mount the root file system in / mnt / and fix the bug there already.