Ubuntu

How to Change the Hostname in Ubuntu 22.04

The hostname is the name of a device that is used to identify your device name over the internet. It gives us the device name information with which we interact physically or on the network without remembering many IP addresses. The hostname is shown on some prominent locations in your system such as in Linux on the terminal prompt.

For our convenience, we can change the hostname of a system in Linux and other operating systems. But, it is necessary to pick some descriptive hostname for your device such as “ubuntu-desktop” instead of choosing an ambiguous one.

This article will demonstrate how to change the hostname in Ubuntu 22.04 Linux Jammy Jellyfish system. We will explore the list of all possible methods used for changing the hostname in Linux distributions.

How to Change the Hostname in Ubuntu 22.04

We can change the hostname in Ubuntu 22.04 LTS system by following the two different methods:

  1. Change the hostname in Ubuntu 22.04 system using GUI
  2. Change the hostname in Ubuntu 22.04 system using the command line

How to Change the Hostname in Ubuntu 22.04 LTS Using GUI

Most Ubuntu users want to change the hostname using the Gnome desktop environment. Therefore, we can change the hostname using the GUI after performing the following steps:

  • Click on the top-right corner of your Ubuntu 22.04 LTS desktop. Then, click on the “Settings” option to open the settings menu.

  • Navigate into the “About” tab after scrolling down the page. You will see the device name on the right side of the settings menu.

  • Now, click on the “device name”. A new dialog box pops up on the settings menu. Here, type the hostname that you would like to use for your device.
  • Once you changed the hostname, click on the “Rename” button to change the hostname. Now, you can close the settings menu.

  • You can also verify the changes, open the terminal, and type the following command:
$ hostname

This command shows you the updated hostname in the output.

How to Change the Hostname in Ubuntu 22.04 Using the Command Line

Changing the hostname in Ubuntu 22.04 using the command line is quite a simple and easy process. First, print the current hostname of your device. You can check the hostname of your system either by using the “hostname” or via the “hostnamectl” command:

$ hostname

The “hostnamectl” command shows you more information about the hostname.

$ hostnamectl

Different ways are available to change the hostname in Ubuntu using the terminal.

Method 1: Changing the Hostname Temporarily in Ubuntu 22.04 Using the Hostname Command

The hostname command allows you to temporarily change the hostname of your system.

$ sudo hostname linuxhint

Method 2: Changing the Hostname Using the Hostnamectl Command

Most Linux distributions including Ubuntu 22.04 have a command line tool “hostnamectl” to manage the system hostname. Using the hostnamectl command, you can change your device name. This command allows you to change the hostname permanently without rebooting your system.

$ sudo hostnamectl set-hostname linuxhint

Method 3: Changing the Hostname in the Hostname Configuration File /etc/hostname

We can change the hostname by directly modifying the configuration file. But, after changing the hostname, you need to restart your system to make the changes take effect!

Open the configuration file “/etc/hostname” and edit it using the following command:

$ sudo nano /etc/hostname

Now, replace the hostname with your new hostname:

Press “Ctrl+O” to save the changes and “Ctrl+x” to exit from this window.

How to Change the Hostname in Ubuntu 22.04 in the /etc/hosts File

No matter which method you are using to change the hostname, after changing the hostname, it is recommended for you to also do these changes in the configuration file “/etc/hosts”. This configuration file contains the old hostname, IP mapping, etc. It is important to change the hostname in this file. To edit the hostname in the “/etc/hosts” file, open this file:

$ sudo nano /etc/hosts

Now, do the following changes:

127.0.0.1 localhost

127.0.1.1 linuxhint

Save the changes by pressing “Ctrl+O” and then “Ctrl+X” to exit from this screen.

Conclusion

In this tutorial, we learned how to change the hostname in Ubuntu 22.04 LTS Jammy Jellyfish Linux distribution. Changing the hostname is a simple and small task that we can do using multiple ways. In this tutorial, we changed the hostname using two different methods using the terminal and GUI. I hope all the discussed details are informative for you.

Similar Posts