Linux Mint

How to Change Hostname on Linux Mint 20

Hostname enables us to identify a device over the network. The hostname is set on your device during the installation process, or we can change it anytime on our virtual machine. A conflicting situation can arise if more than one device has a similar hostname and is connected to the same network.

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:

$ hostnamectl

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:

$ hostnamectl

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:

$ hostnamectl

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:

$ hostnamectl

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:

$ sudo nano /etc/hosts

Let’s change the linuxhint to Linux, save, and exit the file.

The hostname will be updated successfully.

Conclusion

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.

About the author

Kamran Sattar Awaisi

Kamran Sattar Awaisi

I am a software engineer and a research scholar. I like to write article and make tutorial on various IT topics including Python, Cloud Computing, Fog Computing and Deep Learning. I love to use Linux based operating systems.