The hostname is a unique identifier for a Linux machine within a network. It is typically set during system installation and stored in the /etc/hostname file.
You can view the current hostname by using the hostname command, examining the contents of the /etc/hostname file, or observing it in the command prompt when you log into the system.
There are several ways to change the system's hostname, such as editing the /etc/hostname file directly or using the hostname command. However, the recommended approach is to use the hostnamectl tool. This tool is specifically designed for managing hostnames and ensures that the changes persist after a system reboot. By using hostnamectl, you can avoid misconfigurations and make sure your changes are applied correctly.
Steps to change hostname in Linux:
- Open a terminal application.
- Check the current hostname.
user@host:~$ hostname host
- Use hostnamectl to change the hostname.
user@host:~$ sudo hostnamectl set-hostname newhost
- Verify the new hostname by checking it again.
user@host:~$ hostname newhost
- Examine the /etc/hostname file to ensure the change has been saved and will persist.
user@host:~$ cat /etc/hostname newhost
- Open a new shell to test if the change has been successful.
user@host:~$ bash user@newhost:~$

Mohd Shakir Zakaria is a skilled cloud architect with a background in development, entrepreneurship, and open-source advocacy. As the founder of Simplified Guide, he helps others understand the complexities of computing, making tech concepts accessible to all.
Comment anonymously. Login not required.