Setting Hostname Temporarily and Permanently in Linux

Let us check out how to set a hostname temporarily and permanently in Linux:

Temporarily:

Step 1: Check the Current Hostname

First, you need to check the current hostname of the device by using the hostname command in terminal

hostname

Output:

Hostname displayed

This command displays the current hostname of your Linux machine. We can see that the hostname of our machine is Kali.

Step 2: Set the Hostname Temporarily

Here we are setting the temporary hostname as w3wiki using the command sudo hostnamectl set-hostname <name> and entering the sudo password. Replace <name> with your desired hostname. This change is temporary and will be lost after a system reboot.

sudo hostnamectl set-hostname <name>

Output:

Hostname set to w3wiki

Step 3: Verify Hostname Changes

You can verify the change in hostname by using the hostname or hostnamectl command in the terminal, which will display the temporary hostname we created.

hostname
hostnamectl

Output:

Ensure that the changes are reflected in the system.

How to Set Hostname Permanently in Linux

Setting a hostname is a fundamental step in configuring a Linux system. The hostname acts as an identifier for your machine on a network, making it easier to manage and communicate with other devices. In this article, we’ll explore the importance of having a well-defined hostname and the process of setting it permanently in a Linux environment.

A hostname not only gives the recognition of your system but also has a crucial role in networking. Whether you’re on a local network or the internet, you should have a clear and identifiable hostname for the administration of your Linux machine.

You can set a temporary hostname using the hostname command while a permanent hostname configuration stays the same even after reboots. This article lets you know how to configure a permanent hostname, understand the relevant configuration files, and the necessary steps to apply the changes.

Similar Reads

Setting Hostname Temporarily and Permanently in Linux:

Let us check out how to set a hostname temporarily and permanently in Linux:...

Permanently:

Step 1: Check the Current Hostname...

Setting Hostname Permanently From GNOME Settings

Step 1: Open Settings...

Setting Hostname From Network Manager TUI

Step 1: Check the Current Hostname...

Conclusion:

In conclusion, setting a hostname in Linux includes both temporary and permanent steps. It is essential for customization and system identification. While temporary changes are used for immediate needs, making permanent adjustments ensures that the chosen hostname stays the same even after reboots. We can change the hostname temporarily by using the sudo hostnamectl set-hostname command and permanently by changing the hostname to “/etc/hostname and /etc/hosts” It will reflect changes in the hostname even after the reboot. You can also use GNOME and NetworkManager TUI to set the hostname permanently. You can follow the simple steps in the article to change the hostname of a Linux machine permanently...