How to change the server hostname on CentOS

February 14, 2024 / Dedicated Server

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:

  1. Edit the Network Configuration:
    1. 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
    2. Change the line to:
      HOSTNAME=myserver.domain.com
  2. Update the Hosts File:
    1. 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.
    2. The content should resemble the following format:
      127.0.0.1             localhost localhost.localdomain
      
      192.168.1.27         myserver.domain.com  myserver
  3. 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.

    1. To change the hostname, run:
      hostname myserver.domain.com
    2. To verify the change, simply type:
      hostname
    3. You should see:
      domain.com
  4. 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!

Spread the love