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:
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:
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.