[Solved] “Error message “sudo: unable to resolve host (none)””


In Linux systems, the hostname is the label or identifier assigned to the system. It is used to identify the system within a network or to distinguish it from other systems. The hostname is usually a combination of a name and a domain name, separated by a dot (.) character.

Sometimes, changing the hostname and switching to it will invoke an error, “[Solved] “sudo: unable to resolve host (none).” The error message “sudo: unable to resolve host (none)” indicates that the system is unable to resolve its hostname.

This post will elaborate on the possible reasons and the best solutions to get you out of this error. The error can be encountered on any Linux distribution. So, the commands provided in this post apply to all Linux-based systems. However, the practical representation shown in this post is performed on Ubuntu 22.04.

How to Fix the “sudo: unable to resolve host (none)” Error?

The error message “sudo: unable to resolve host (none)” in Linux can occur due to a few different reasons:

Incorrect /etc/hosts Configuration

The /etc/hosts file maps hostnames to IP addresses and is used by the system for name resolution. If this file is misconfigured, or if the hostname of the system does not exist in this file, it can result in the “sudo: unable to resolve host (none)” error.

Incorrect /etc/hostname File

The /etc/hostname file contains the current hostname of the system. If this file is missing or contains an incorrect hostname, it can result in an error message.

Network Configuration Issues

If there are network configuration issues or DNS resolution problems, it can result in the “sudo: unable to resolve host (none)” error.

Incorrect Permissions on Files

The error can also occur due to incorrect permissions on files, such as /etc/hosts and /etc/hostname.

The error message “sudo: unable to resolve host (none)” indicates that the system cannot resolve its hostname. This can happen if the hostname has been changed or there is a misconfiguration in the system’s network settings.

Solution: Configure the /etc/hosts File

The best possible solution is to configure the “/etc/hosts” file and check for the hostname entry in the file. Before that, you need to ensure that the hostname exists. So, it’s a sequential process which is illustrated below as follows:

Step 1: Set the Hostname

Check the hostname of the system by running the following command:

$ hostname

hostname

If the output of this command is not the correct hostname of your system, you can change it via the following command, i.e., the command will set the hostname to “genie”:

$ sudo hostnamectl set-hostname genie

set hostname

Replace “genie” with the new hostname you want to set.

Step 2: Configure the Hostname

Check the contents of the /etc/hosts file by running the following command:

$ cat /etc/hosts

check hostname

The contents of this file should include an entry for the current hostname of the system. If it does not (as in our case, because the hostname genie is not in the list), you can add it manually by editing the file with a text editor:

$ sudo nano /etc/hosts

Add a line to the file that includes the IP address of your system and the hostname:

$ 127.0.0.1 genie

configure hostname

Remember to replace “genie” with the correct hostname of your system.

Step 3 (Optional): Restart Networking Service

If you are still facing the same issue, it might be your Network Settings or the DNS server not configured prosperity. To rectify this, it is recommended to restart the networking service on your Linux system using the command provided below:

$ sudo systemctl restart NetworkManager

restart network manager

That’s how you can fix the error “unable to resolve the host” in Linux.

Wrap Up

In Linux-based systems, The Error message “sudo: unable to resolve host (none)” appears when your Linux system does not recognize the hostname. As a result, whenever you use the sudo command with that hostname, you will get the error prompt, “Error message “sudo: unable to resolve host (none).” This error does not interrupt the execution of the command.

The users need to configure the host’s file and check whether the hostname is written correctly or not. If not, manually insert it in the “/etc/hosts” file against the IP address 127.0.0.1. This post has practically demonstrated all the possible solutions. For more troubleshooting tips and tricks, keep visiting and supporting Linux-Genie.

Print Friendly, PDF & Email
Categories