Skip to content

Unable to Resolve Host

If every sudo command prints:

sudo: unable to resolve host my-server: Name or service not known

The server’s hostname is missing from /etc/hosts, usually after you change the hostname. Commands still run, but each one waits for the failed lookup first.

Check the current hostname:

Terminal window
hostname

Open the hosts file:

Terminal window
sudo nano /etc/hosts

Add a line with the hostname, or change the old hostname on the existing 127.0.1.1 line:

127.0.1.1 my-server

Save with Ctrl+X, then Y and Enter. The warning stops on the next sudo command.