CentOS 6 modify the hostname (hostname) need to modify two places: one is /etc/sysconfig/network, the other is /etc/hosts, only modifying any one will cause the system to start abnormally. First switch to the root user. This complete Change Hostname guide walks you through everything step by step.
vi /etc/sysconfig/network
Open the file, there is a line HOSTNAME=localhost.localdomain (if it is the default), modify localhost.localdomain to your hostname.
vi /etc/hosts
Open the file, there will be a line 127.0.0.1 localhost.localdomain localhost. Among them, 127.0.0.1 is the local loop address, and localhost.localdomain is the hostname, which is what you want to modify. localhost is the alias of the host name, which will appear at the Konsole prompt. Change the second item to your hostname, the third item is optional.
After the above two files are modified, they will not take effect immediately. If you want to take effect immediately, you can use
hostname your-hostname
For temporary modification, it only temporarily modifies the host name, and it will be restored after the system restarts. But modifying the above two files is permanent, and restarting the system will get the new host name.
Finally, check the host name after restarting:
uname -n
Change Hostname – Key Takeaways
To get Change Hostname working properly, follow each step in the guide above in order. If something doesn't work, revisit the prerequisites and try again.
Related Guides
- How to Install WordPress on CentOS: A Step-by-Step Guide (see official CentOS documentation).
- How to Install Moodle on Ubuntu
- Install ViciDial On centos 7 And Ubuntu 18
Key Takeaways
- This guide covered changing hostname on CentOS step by step, from prerequisites to verification.
- Always test changes on a staging server before applying them in production.
- Keep backups of your configuration files so you can roll back quickly if needed.
- For related tutorials, see our other guides on email servers and VPS management.
Troubleshooting Tips
If you run into issues while changing hostname on CentOS, check the system logs first — most errors leave a clear trace in /var/log/. Make sure all required packages are installed and your firewall allows the necessary ports. Restarting the relevant service often resolves transient failures. If a step fails consistently, verify file permissions and ownership, as incorrect permissions are a common cause of silent failures on Linux servers.
Frequently Asked Questions
Do I need root access? Yes, most server administration tasks require root or sudo privileges.
Will this work on other Linux distributions? The concepts apply broadly, though exact commands and file paths may differ between distributions.
How do I verify it worked? Follow the verification steps in the guide above and check the service status with systemctl status.