The hostname is a key identifier for a Linux system on a network. It helps other machines recognize and communicate with your system. The hostname is usually configured during the initial system setup and stored in the /etc/hostname file.
You can view the current hostname by using the hostname command or checking the contents of the /etc/hostname file. It can also be seen directly in your command prompt when you log in. Understanding how to check and change the hostname is essential for proper network management.
To change the hostname, it is recommended to use the hostnamectl command. This tool is designed to update the hostname effectively and ensures that the change persists after a reboot. Using hostnamectl prevents potential misconfigurations and ensures the new hostname is applied correctly.
Steps to change hostname in Linux:
- Open the terminal.
- Check the current hostname.
user@host:~$ hostname host
- Use hostnamectl to set a new hostname.
user@host:~$ sudo hostnamectl set-hostname newhost
- Verify the new hostname.
user@host:~$ hostname newhost
- Ensure the change is saved in the /etc/hostname file.
user@host:~$ cat /etc/hostname newhost
- Open a new terminal session to confirm the hostname has been updated.
user@host:~$ bash user@newhost:~$
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Comment anonymously. Login not required.