What Is a Hostname, and How Do You Change It?

When you set up your Linux system—whether it’s a VPS or a physical machine in your home—you may be asked to provide a hostname. This is a label your computer uses to identify itself to other machines on the network, to the user, and to itself.

Hostnames should be descriptive so that it’s easy to identify machines—even when you’re not sitting directly in front of them. “Kitchen PC”, or “David’s tiny laptop” are great names. “racknerd-b7516a” is a terrible name and makes it difficult to work out exactly which machine you’re connected to.

One way of changing the hostname on Ubuntu or other Debian-based Linux distros is with the terminal.

Open a terminal by either pressing Ctrl + Alt + T, or by selecting it from your menu system, then enter:

Log out and then log back in, and you will see that the hostname has changed.

What Does “unable to resolve host: Name or service not known” Mean?

After changing your system’s hostname, the next time you try to run a command as sudo, you might receive a hostname error. In our case, the error was “unable to resolve host MUOVPS: Name or service not known”.

This error does not prevent you from carrying out any tasks, but it can be annoying.

The aforementioned command will show the hostname you just set, but your new hostname is not present as an output of:

To fix this error, use nano to edit the file:

On a new line, add the hostname of your machine—the hostname of our VPS is MUOVPS as shown below—then save and exit nano with Ctrl + O then Ctrl + X.

You Have Fixed the “unable to resolve host” Error!

Hostname errors are not the most serious and are unlikely to significantly disrupt your workflow or your day. But they are annoying and show that you haven’t configured your system properly. For this reason, it’s worth setting the hostname properly.

Fixing this issue requires you to edit the /etc/hosts file. Since it is a critical system file, knowing how to edit it properly is important to prevent any errors.