
{{ $('Map tags to IDs').item.json.title }}
How to Change Hostname in Linux
Changing the hostname of a Linux system is a common administrative task. The hostname is the name that identifies the machine on a network. This tutorial will guide you through the steps to change the hostname in various Linux distributions.
1. Checking the Current Hostname
To view the current hostname of your system, use the following command:
hostnamectl
This command will display the current hostname along with other related information.
2. Changing the Hostname in Ubuntu
On Ubuntu systems, you can change the hostname using the hostnamectl
command:
sudo hostnamectl set-hostname new-hostname
Replace new-hostname
with your desired hostname. To verify the change:
hostnamectl
3. Changing the Hostname in CentOS/RHEL
For CentOS and RHEL systems, you can also use the hostnamectl
command:
sudo hostnamectl set-hostname new-hostname
Additionally, update the /etc/hostname
file manually:
sudo nano /etc/hostname
Replace its content with the new hostname and save the file.
4. Editing the Hosts File
After changing the hostname, it’s a good practice to update the /etc/hosts
file:
sudo nano /etc/hosts
Change the lines corresponding to your old hostname:
127.0.0.1 localhost
127.0.1.1 new-hostname
Save the changes to ensure your system recognizes the new hostname.
5. Rebooting the System
Although the hostname change is effective immediately, it is advisable to reboot your system to ensure all services recognize the new hostname:
sudo reboot
6. Conclusion
By following these steps, you have successfully changed the hostname on your Linux system. Keeping your hostname updated can help with network identification and improve organization within your server environment. Continue to explore Linux system administration to handle more advanced configurations!