How to Change Hostname in Ubuntu 22.04

change hostname in ubuntu

In the ever-evolving landscape of Linux distributions, Ubuntu stands as a beacon of user-friendly functionality and versatility. As the community awaits the release of the next LTS version, each day system admins and enthusiasts alike are drawn to the plethora of opportunities promised. One of the most basic and commonly overlooked aspect of system customization is the ability to change the hostname in Ubuntu.

In this guide, we will look at multiple ways you can change hostname in Ubuntu 22.04 along with the reasons you might need to do this. Whether just for showing your personality on the network or for any other purpose, let’s get into this and explore it all.

Also, read How to change Hostname in Ubuntu 24.04.

What is a hostname?

A hostname is like the cozy nickname your computer gets in the big, bustling world of the internet. It’s a user-friendly label that’s way easier to remember than a string of numerical IP addresses. Essentially, it’s the unique name assigned to your device on a computer network, making it stand out and be easily recognizable. Picture it as the digital nameplate for your computer, helping it seamlessly communicate with others in the network. So, whether you’re navigating the vastness of the internet or cruising through a local network, your hostname is the friendly identifier that keeps things running smoothly.

How to identify the current hostname?

Curious to know what name your Ubuntu 22.04 system goes by? Well, it’s as easy. Just pop open the terminal and execute:

$hostname

 Voila! Your system spills the beans, revealing its current hostname right there. Or if that doesn’t do the trick, you can also try:

$hostnamectl

Method 1:  Changing the hostname for the current session only

The “hostname” command can be used to manage the hostname of the system. To change the hostname for the current session, you can use the following command:

$sudo hostname NEW_HOSTNAME

Replace NEW_HOSTNAME with the new hostname you want to use. For example, to change the hostname to “super-server”, you would use the following command:

$sudo hostname super-server

This will change the hostname for the current session, but it will not persist after a restart. If you want the new hostname to be permanent, you will need to edit the “/etc/hostname” file. To see the changes take effect, you’ll need to run the following to refresh your current session:

$newgrp

Remember that this name change will revert once you restart your computer.

Method 2: Changing the hostname permanently

To change your Ubuntu 22.04 hostname permanently without the need for a system reboot, you can use the “hostnamectl set-hostname” command. Execute the following command, replacing “new-one” with your desired hostname:

$sudo hostnamectl set-hostname new-on

Similar to the last method, you will need to refresh the session using:

$newgrp

Method 3: Changing the hostname by editing the /etc/hostname file

To make the hostname change permanent, you need to edit the /etc/hostname file. This file contains the current hostname of the system. To open the file, use the following command:

$sudo nano /etc/hostname

Replace the current hostname with the new hostname you want to use. Save the file and close the editor.

You also need to restart the hostnamed service for the new hostname to take effect. You can do this by running the following command:

$sudo systemctl restart systemd-hostnamed

Just refresh the session again using “newgrp” and you should be good to go:

Method 4: Using the About This Computer settings

There is also a graphical way to change the hostname for the current session. To do this, open the About This Computer settings by clicking on the settings icon in the top right corner of the screen.

Then, in the left pane scroll to the bottom and click on “About”. In the right pane, you will see the Device Name right below the Ubuntu logo. Don’t be confused as the Device Name is exactly the same as hostname. You can click on it to pull up a dialog box to change it.

After changing the name, click on the greeb rename button in the upper right corner to apple the change.

This will change the hostname for the current session, but it will not persist after a restart.

Conclusion

Changing the hostname in Ubuntu 22.04 is a straightforward process that can be accomplished using either the command-line or graphical interface. By following the simple steps outlined in this article, you can effectively rename your system and maintain consistent identification on your network.

Keep visiting Linux World.