How to Change Ubuntu 24.04 Hostname Permanently

A hostname is the username assigned to a system to identify it on a network. It works as a system’s unique identity. That’s why hostnames should be unique and different; otherwise, multiple systems with the same name over a single network can create a mess.

The hostname is set when the user installs their operating system. However, changing the hostname becomes crucial in different situations, such as avoiding conflicts, improving security, meeting software requirements, etc. Hence, this blog is about the methods to change the hostname in Ubuntu 24.04 permanently. The hostname is essential in various server management tasks and network operations. There are several methods for changing the hostname, but we have only included those that allow you to modify your hostname permanently.

Before moving further, it is essential to check the current hostname. For this, just type ‘hostname‘ in the terminal as follows:

This is how you can get your current hostname.

sudo hostnamectl set hostname

The hostnamectl Command to Change hostname on Ubuntu 24.04

The hostnamectl is one of the most straightforward commands that you can use to modify the hostname permanently:

sudo hostnamectl set-hostname <new_hostname>

Here, we change the hostname from ‘prateek‘ to ‘PRATEEK‘ by running the below command:

sudo hostnamectl set-hostname PRATEEK

You can also run the hostnamectl command to verify that your hostname has changed successfully.

hostnamectl command

Although the result shows the new hostname, remember it has not been permanently changed.

That’s why you must edit the host file to modify the hostname permanently. This file maps hostnames to IP addresses, so this change is required when a user needs to resolve the IP address with the hostname.

 So let’s open the ‘/etc/hosts’ file through the following command:

sudo edit /etc/hosts

As you can see, the existing hostname is ‘ prateek,’ and we need to change it.

see the existing hostname

We have changed the hostname from ‘prateek’ to ‘PRATEEK.’

After completing the above process, you must restart your system to make changes successfully.

changed the hostname

Using GUI System Settings to Change Hostname

Although this method can’t change the hostname permanently, you can use it when the above method doesn’t work. For this, you need to follow some general steps:

1. First, search ‘settings‘ in the search bar and open the application.

Open Ubuntu Settings

2. Next, in the left bar menu, click on the system > about:

About the System

3. Here, you will see an option named ‘Device name,’ where you can change your hostname.

Gui to change hostname ubuntu 24.04

4. Afterward, you can apply the changes, and the hostname will be temporarily changed.

Hostname rewrtie Ubuntu


That’s how you can permanently change the hostname on Ubuntu 24.04. The ‘hostnamectl‘ command is the straightforward and most uncomplicated way to do this, and you also need to change it in the ‘/etc/hosts‘ file. This step ensures complete and permanent changes in the system. Users who prefer the GUI method can use the System Settings, but it will only temporarily help you change the hostname.





Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.