Explaining the Hostname
In Linux Mint, we can get the hostname information and edit it using the hostnamectl command. There are following three different types of hostname in Linux Mint:
- Static: It is a standard hostname displayed over the network and is saved in the /etc/hostname file.
- Pretty: The pretty hostname is not displayed on the network. It is only displayed to the user.
- Transient: The transient hostname is the same as the static hostname by default. The Kernel maintains it.
Check the current hostname
We can check the current hostname of the device by using the hostnamectl command:
My current static hostname is Linux.
Changing the Hostname on Linux Mint 20
We can change the Hostname on Linux Mint by two methods:
- By using the hostnamectl command
- By editing the /etc/hostname file
We will discuss these two methods for changing the hostname.
Using hostnamectl command to change the hostname
It is very simple and straightforward to change the hostname by using the hostnamectl command. Follow the below-given command syntax to change the hostname:
$ sudo hostnamectl set-hostname <new-hostname>
I am changing my Linux Mint system hostname to linuxhint from Linux:
$ sudo hostnamectl set-hostname linuxhint
Now let’s check our new hostname with the command:
As you can see from the output that my static hostname is changed to linuxhint.
To change the pretty hostname, use the hostnamectl command with –pretty option as follows:
$ sudo hostnamectl set-hostname “Kamran’s laptop” –pretty
To check the pretty hostname, use the command:
The pretty hostname value is updated.
Changing the hostname from /etc/hostname file
Open the /etc/hostname file in the nano editor by typing on the terminal:
$ sudo nano /etc/hostname
The /etc/hostname file opened in the nano editor.
Now, change the hostname here.
Once you have changed the hostname, save the file and run the hostnamectl command again:
You can see that the static hostname is changed to Linux.
In many situations, the hostname is mapped to the localhost (127.0.0.1). This information is stored in the /etc/hosts file. Open the /etc/hosts file and change the hostname:
Let’s change the linuxhint to Linux, save, and exit the file.
The hostname will be updated successfully.
We can change the hostname on Linux Mint 20 in a couple of ways, i.e., from the hostnamectl command and by editing the /etc/hostname file. This article explains the hostname and describes the methods to change the hostname on Linux Mint 20 system.