How to change hostname in CentOS

centos. server vps

How to change hostname in CentOS

How to Change the Hostname in CentOS VPS Server 


When managing a CentOS VPS server, one of the essential tasks is to change the hostname to reflect its purpose or role in your infrastructure. A hostname is a human-readable label that corresponds to a device on a network. This guide will walk you through the process of changing the hostname in CentOS, ensuring your system is accurately identified. 


Before we dive into the steps, there are a few prerequisites: 

You need access to your CentOS VPS server. 

Basic knowledge of command-line operations is required. 

Step 1: Check Current Hostname 

First, let’s check the current hostname. Open your terminal and run: 


hostname of your server
This command will display the current hostname of your server. It’s crucial to know this before making any changes.

Step 2: Edit /etc/hostname File 

Next, we need to edit the /etc/hostname file. This file stores the hostname that the system will use. Open it using a text editor like nano or vi:  

sudo nano /etc/hostname

hostname of your server 02

Replace Current Hostname: Replace the current hostname in the file with the new hostname you want to set, and then save the changes.

Replace Current Hostname

Edit /etc/hosts File: Open the /etc/hosts file using a text editor:

sudo nano /etc/hosts

Update Hosts File: Locate the line containing the old hostname and update it with the new one. It typically looks like:   localhost old_hostname

Change it to:   localhost new_hostname

 change hostname in CentOS 03

Apply Changes: After updating both files, you need to activate the new hostname without restarting your system. Run the following command:

sudo hostnamectl set-hostname new_hostname

 change hostname 04

Verify Changes: Confirm that the new hostname is set correctly by running:



 change hostname in CentOS 05


After following these steps, your CentOS system should have the new hostname configured.

Common Issues and Troubleshooting 

Sometimes, the hostname might not update as expected. Ensure you have the correct permissions to edit the files and that you have saved your changes properly. If issues persist, double-check the steps and file paths. 

Automating Hostname Changes 

For those managing multiple servers, scripting the hostname change can save time. Alternatively, configuration management tools like Ansible can automate this process across your infrastructure. 

Best Practices 

When choosing a hostname, ensure it’s meaningful and descriptive. Documenting any changes made to the server configuration is also a good practice, aiding future troubleshooting and maintenance. 

Security Considerations 

Hostnames play a role in your server’s security. Avoid using sensitive information in your hostname and ensure it doesn’t reveal critical details about your server’s role or purpose. 

Hostname in Network Configuration 

Hostnames are crucial in network identification and communication. They interact with DNS to resolve to IP addresses, helping devices locate each other on a network. 

Advanced Configurations 

For advanced users, configuring dynamic hostnames or integrating hostname changes with DHCP can provide more flexibility and automation in managing networked devices. 


Changing the hostname in a CentOS VPS server is a straightforward process that enhances the manageability and organization of your network. By following the steps outlined above, you can ensure your server is properly identified and configured. 


What is a Hostname? 

 A hostname is a human-readable label assigned to a device on a network, making it easier to identify and communicate with. 

Why Change the Hostname?  

Changing the hostname helps in better managing and organizing your network, especially when running multiple servers. 

Can I Change the Hostname Without Rebooting? 

 Yes, using the hostnamectl command allows you to change the hostname without restarting the system. 

What If I Encounter Errors? 

 Ensure you have the correct permissions and have saved your changes. Double-check the file paths and command syntax. 

How Do Hostnames Affect Networking? 

 Hostnames are crucial for network identification and communication, interacting with DNS to resolve IP addresses and facilitating device connectivity. 



Post Your Comment

Free Migration Assistance

If you need assistance with migrating your current data from another provider, we would be more than happy to assist.

Limited Special Promo Code - Free Setup on all VPS plans when using code
This is default text for notification bar