How to change Hostname on Ubuntu 24.04

Change hostname in ubuntu 24.04

Remembering the IP addresses for your system might be difficult, which makes it harder to identify it when connected to any network. To address this issue of identification, every system has a human-readable name, usually called a hostname. In Ubuntu 24.04 and other Linux distributions, there are several hostnames, each serving a specific purpose. The hostname on Ubuntu 24.04 can be changed in various ways depending on the type of hostname.


How to Check Hostname on Ubuntu 24.04

To begin with, changing the hostname on Ubuntu it is necessary to know the types of hostname along with the purpose of each type. First, check the hostname for your system by using hostnamectl:


Here, as you can see, three different hostnames are set for my Ubuntu 24.04:

Types of Hostname in Ubuntu 24.04

As mentioned above there are three types of hostnames for every Linux distribution and each serves a different purpose, these are the three types:

  • Static hostname: The primary hostname configured in the system host file. It is primarily used by local services and applications to identify the system.
  • Transient hostname: This hostname is dynamically assigned based on the configuration of the network and is usually generated by the network service.
  • Pretty hostname: This is an informal name that is set by the user having numbers or special characters in it. Unlike the other two types, there are no restrictions for this type and does not affect the system functionality.

How To Change Hostname on Ubuntu 24.04

Setting the hostname to the desired one can be crucial if you want to name it after the name of its user or after the task for which it will be used. This helps in the segregation of systems, resulting in much better control for monitoring or debugging.

The four possible methods to change the hostname are demonstrated here:

1: Through hostname Command

If you are looking to change the transient hostname of your Ubuntu 24.04 then use this method, this utility is not only changes it but also used to display the transient hostname. To change the temporary hostname on Ubuntu via the hostname command execute:

sudo hostname <enter-desired-hostname>

Now, after you have set the desired hostname, verify it by using the hostnamectl utility, and remember that this hostname will change once the device is rebooted:


2: Through hostnamectl Command

The static hostname remains the same even if the system is rebooted, so to change it use the hostanmectl utility. This command is also used to display the operating system information apart from changing the hostname:


To change the static hostname use the set-hostname and give the desired hostname for your Ubuntu:

sudo hostnamectl set-hostname <enter-desired-hostname>

By using the hostnamectl utility to change the hostname, the new name is automatically added to the system hostname file. To verify the static hostname change, you can read the hostname file:

cat /etc/hostname

Further, if you want to add a cool name for your system then use the pretty flag as in the syntax below:

hostnamectl set-hostname "<enter-desired-hostname>" --pretty

Note: If the static hostname is already set using the hostnamectl command then the same name will be used as transient. So to change the transient hostname, you need to use the hostname command and restart the terminal session:

hostnamectl set-hostname "<enter-desired-hostname>" --transient

3: Through Ubuntu System Settings

Another way to set the fancy name for your system is by using the Ubuntu system settings. First, navigate to the Users tab in system settings and then write the desired name afterward click on the tick mark to save the changes:

4: Through Network Manager

The alternative way to set the static name is by using the Ubuntu network manager. The network manager comes with both the command line and the GUI interface. To use the GUI interface, execute:


First, select the set system hostname option and proceed by clicking OK:

Now enter the desired static hostname and then click OK to apply the changes:

Since this is the static hostname that remains persistent to prompt the change enter the system authentication code:

After the changes are successful, click on Quit to exit the network manager:

Further, you can verify the change by executing the hostnamectl command:


To use the command line version of Ubuntu network manager use the below given syntax:

sudo nmcli general hostname <enter-desired-hostname>

To verify the change of username execute the hostname command with the general keyword:

nmcli general hostname

5: Through machine-info File

To change the pretty hostname on Ubuntu you can create a machine-info file and enter the desired fancy name for your system:

sudo nano /etc/machine-info

You can verify the set hostname by executing:


6: Through hostname File

To change the static hostname manually on Ubuntu you can add the desired name in the hostname file:

sudo nano /etc/hostname

You can verify the set hostname by executing:


Note: Using the hostnamectl command and the Ubuntu network manager changes the transient hostname as well so that’s why the hostnamectl command doesn’t show the transient one as it is the same as the static one. You can execute the below commands to verify:

hostnamectl --transient

hostnamectl --static


The hostname of any system is an easy way to identify it when connected to a network with which other devices are connected. Hostname on Ubuntu can be changed in six different ways, but the prominent ones include using system user settings, hostnamectl command, hostname command, and Ubuntu Network manager. All these are demonstrated briefly on the latest LTS release of Ubuntu, i..e, 24.04 Noble Numbat.

Similar Posts