This knowledge base article guides users through the process of changing the dedicated server hostname on a CentOS server. By default, your server is assigned a hostname based on the server’s given name. Some control panel software, such as cPanel and DirectAdmin, requires a valid Fully Qualified Domain Name (FQDN) for hostname verification during their licensing process.
Steps to Change the Hostname:
- Edit the Network Configuration:
- Open the /etc/sysconfig/network file using your preferred text editor, such as vi or nano. Locate the HOSTNAME= line and modify it to reflect your desired FQDN hostname.
sudo nano /etc/sysconfig/network
- Change the line to:
HOSTNAME=myserver.domain.com
- Open the /etc/sysconfig/network file using your preferred text editor, such as vi or nano. Locate the HOSTNAME= line and modify it to reflect your desired FQDN hostname.
- Update the Hosts File:
- Next, you need to update the host file, which associates your main server IP address with the new hostname. This file is located at /etc/hosts.
- The content should resemble the following format:
127.0.0.1 localhost localhost.localdomain 192.168.1.27 myserver.domain.com myserver
- Set the Hostname:
You can change the hostname temporarily by using the hostname command in the terminal. However, note that this change will not update all running programs that still use the old hostname.- To change the hostname, run:
hostname myserver.domain.com
- To verify the change, simply type:
hostname
- You should see:
domain.com
- To change the hostname, run:
- Restart Networking:
Finally, to apply all changes, restart the networking service on your server. Execute the following command:/etc/init.d/network restart
Now you have successfully changed the hostname on your CentOS server!
Feel free to let me know if you need any more changes or additional information!