How to change the hostname in Ubuntu Linux

User Avatar
πŸ‘€ admin
πŸ”΄ Admin
✍️ The most important thing in the world is to not be alone.
⏳ Last active: 15 Apr 2025 at 16:01
πŸ“… Created: 11 Apr 2021 at 21:10
πŸ‘€ Viewed: 19 times
βœ‰οΈ Send Email

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

Image

Changing the hostname:

To change the hostname we are going to use hostnamectl


# Change machine hostname

sudo hostnamectl set-hostname new-hostname

Image

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

Image

Check if changes are correct

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


# Check changes

sudo hostnamectl

Image

Restarting

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


# Reboot

sudo systemctl reboot

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

https://youtu.be/M9NlfqB0RJ8

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

If you want to comment: Login or Register