How to Change Hostname on Ubuntu 22.04

A hostname is a custom name created by the user. This name also differentiates a particular device from others within a local network. Moreover, this name makes an operating system recognizable in the network, thus making the data exchange within the same network easy.

Like any other operating system, Ubuntu also allows its users to provide a certain username. If you wish to change this username on Ubuntu 22.04 then there are two possible ways to do it:

  • change hostname using command line
  • change hostname using GUI

Here we have discussed both of these in detail.

How to change hostname using command line on Ubuntu 22.04

Below we have guided you step-wise on how to change hostname using the command line on Ubuntu 22.04.

Step 1: Check new hostname

Before jumping toward changing the hostname, let’s first evaluate the current hostname of our system.

$ hostname


So the current hostname is “linuxBox”.

Step 2: Change hostname

Now that we know what our current hostname is. Let’s change it using the following command.

$ sudo hostname ubuntuUser

Using the above command we are setting our new hostname as “ubuntuUser”.


Hostname has been changed.

How to change hostname using GUI on Ubuntu 22.04

Another approach to changing the hostname is through GUI. Here we have enlightened you on how this is done.

Step 1: Open settings

Click on the top right corner where the battery icon, sound icon, and internet icon are displayed. A dropdown menu will pop up. In that menu click on the settings options.

Step 2: Open Device Name

Once clicked, the settings will open and the first option labeled “Device Name” will show you the current hostname. Click this.

Step 3: Change Hostname

Now a message box will open up displaying your previous hostname. Erase that name and insert your new desired hostname and press “Rename”. In our case, the previous hostname was “ubuntuUser”, we are now changing to “linuxBox”,

Voila! The hostname has been changed.

Step 4: Verify Change

Lastly, to make sure that the change was implemented successfully run the following command on the terminal.

$ hostname


The output confirms that the hostname has been changed.


To change the hostname on Ubuntu 22.04 either use the command line or the GUI. In the case of the command line use the command $ sudo hostname newname and change the hostname. However, in the case of GUI go to settings>>Device Name>>enter new hostname>>press Rename. If you wish to evaluate this change run the $ hostname command on the terminal.

About the author

Naima Aftab

I am a software engineering professional with a profound interest in writing. I am pursuing technical writing as my full-time career and sharing my knowledge through my words.