[Fixed] sudo: unable to resolve host

Host or hostname is the specific name of the machine that is helpful over the network for identification purposes. Machines connect to the network and perform functionalities to send or receive packets through this name. Sometimes, an error “sudo: unable to resolve host” comes across while executing the command with root privileges.

This post will discover the possible reasons and the solutions to those reasons.

Let’s start the article.

Reason 1: Hostname Not Configured

At the time of installing the Linux system, most users keep the default setting and do not assign any hostname, which is one of the reasons for the “sudo: unable to resolve host” error. 

Solution: Configure HostName

To encounter the above error, modify the hostname in the “hosts” configuration file. You must access the host’s info file located at “/etc/hosts”.

The Nano Editor is utilized to access and modify the configuration file by specifying the file directory as given below:

$ nano /etc/hosts

The hostname and its IP address are highlighted in the above image (while the first entity is the localhost ).

Change Hostname

Modify the hostname by reaching through the arrow keys and changing the custom hostname. In our case, “myubuntu” is set here:

Restart the system

To apply these changes, type the “reboot” in the terminal to restart the system as below:

$ reboot

Verify the New Hostname

After restarting the system, you can verify that the hostname changes to “myubuntu” from the “ubuntu”:

Let’s see another reason with a solution.

Reason 2: Incorrect Hostname

One of the main reasons for the above error is changing the hostname and executing the “sudo” command in the terminal with the incorrect hostname.

Solution: Check the Hostname of the System

In network devices, the hostname is important to route traffic over the network. To check the hostname on Linux, various command line utilities are used. The hostname is one of them, as seen below.

$ hostname

After executing the above script, the machine’s hostname, “ubuntu”, is displayed here.


In the Linux system, the “sudo: unable to resolve host” error can be resolved by configuring the hostname properly. During configuration, users can modify the hostname through any editor and reboot the system to apply changes. Additionally, the hostname can be displayed by executing the “hostname” command in the terminal.