A hostname is the unique identity of the machine by which it can be recognized in a network, for example, if your machine name is “Alex”, you can easily recognize your machine in the network and can send the documents to it. In Linux, the hostname can be changed any time.
When you open the terminal the hostname is shown in the command as well. In this guide, we will explore methods by which we can make it possible to change the hostname in Ubuntu.
How to change the hostname in Ubuntu 22.04
Before exploring methods to change hostname, let us run the command to find out the current hostname of Ubuntu:
In the above image, we can see that hostname of our machine is “foss” and if we want to display only hostname instead of the other data, we can use the command:
Now if we want to change the hostname, for example, we say that we want to change the hostname from “foss” to “linux”, we will use the command:
$ sudo hostnamectl set-hostname linux
Now to verify the changes, we will again display the hostname using the command:
Another method to change the hostname is by going to the “Settings” and then click on the “Sharing” option:
We will change the “linux” hostname back to “foss” by replacing “linux”:
Go back to the terminal and run the command of displaying hostname:
The name is changed back to “foss”.
The hostname of a machine is the identity or unique name by which we can recognize the machine in the network and in this write-up, we discover methods to change the hostname on Ubuntu 22.04.
The Best Linux Tutorials Website