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.
We can change the hostname in Ubuntu 22.04 LTS system by following the two different methods:
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:
$ hostname
This command shows you the updated hostname in the output.
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.
The hostname command allows you to temporarily change the hostname of your system.
$ sudo hostname linuxhint
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
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.
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.
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.
Welcome to the Ubuntu Weekly Newsletter, Issue 883 for the week of March 9 –…
In this article, we will see how to install nvidia-smi on Ubuntu or Debian Linux.…
In this article, we will see how to install clang tool on Ubuntu or Debian…
When working with Docker containers on Raspberry Pi devices, you might encounter frustrating signature verification…
You’ve recently upgraded to Ubuntu 18.04 and found that your OpenVPN connection no longer resolves…
Have you ever tried to open System Monitor on your Ubuntu 18.04 system only to…