A hostname is the label of any machine that identifies the system by which the system can be accessed from the network. The hostname of any system is a simple string consisting of letters, numbers, dots, and hyphens. The system hostname can be assigned in two main ways, the first way you can set the hostname while installing the operating system and second you can change the hostname from the command line by logging into the system with the root account. In this article, we will explain to you how to change the hostname of the Linux and other Linux distributions system in the command line.
Check Current System Hostname
If you want to check the current hostname of the Linux system, then you have to run the system command in the Linux system terminal.

If you want to change the hostname of the system, type the hostname command, give a single space and type the hostname according to choice.
hostname NEW_HOSTNAME

Edit host file to change hostname in Linux
To change the hostname, you can edit the host file of the Linux system. The host file resides in the /etc/ directory, in the below steps you can understand how to edit the host’s file.
Using vi, nano, or any other text editor open the file in /etc/hostname with the following command delete the old name and type the new one you want to set as hostname, and save the file
sudo vi /etc/hostname
After editing the /etc/hostname file, open the /etc/hosts file, and in this file also write the same name that you want to set as the hostname.
sudo vi /etc/hosts
After successful editing of the above two files then restart the system and after system restart, you will find the changed hostname
In this article, we discuss how to change the hostname in Linux. Hope you liked the article, then share it and comment for any kind of feedback. For similar information visit our other blogs simiservice.com
related article: how to monitor Linux processes with example
