Spread the love

In this tutorial we will learn how to change the hostname of our ubuntu distribution

What is a hostname? On a computer network, the host name is a label that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication, such as the World Wide Web.

If you decide that the name chosen at installation time or assigned automatically is not what you want, you can follow the steps below to update to a new name.

The hostname should be unique on a network and should identify individual machine. There should not be two machines with same hostname.

How to check the current hostname?

You can choose between two commands to find out your current hostname, there are other ways too but we are going to keep it simple and practical.

# Check hostname using lsb_release
lsb_release -a

# Check hostname using hostname control
hostnamectl
Code language: PHP (php)
ubuntu change hostname

Changing the hostname:

To change the hostname we are going to use hostnamectl

# Change machine hostname
sudo hostnamectl set-hostname new-hostname
Code language: PHP (php)
ubuntu change hostname

Changing the pretty hostname

A “pretty” hostname is the hostname presented to the user, not to another computer on a network. A computer system identifies another computer only by its static hostname.

# Change pretty hostname
sudo hostnamectl set-hostname "new-hostname" --pretty
Code language: PHP (php)
ubuntu change hostname

Check if changes are correct

Now we are going to type hostnamectl to check if changes are applied

# Check changes
sudo hostnamectl
Code language: PHP (php)
ubuntu change hostname

Restarting

If all changes are okey for you its time to reboot our ubuntu machine

# Reboot
sudo systemctl reboot
Code language: PHP (php)

Conclusion

This article presented a method in which you can change the hostname on your Ubuntu machine, using the command line tools. The method is simple and straightforward, so you can easily do it.

Here is a video tutorial on the above article

We hope you enjoyed this article. if that is so please rate this page with the stars bellow and subscribe to our YouTube channel.

Leave a Reply