How to Set or Change Hostname in CentOS and Rocky Linux 2025

Changing or setting the hostname in Linux is an important task that helps identify your system on a network. In this guide by Owrbit, we’ll show you a simple way to Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux. These two operating systems, based on Red Hat Enterprise Linux, make it easy to manage your hostname using the command line. Whether you’re a beginner or an experienced user, knowing how to Set Hostname in CentOS and Rocky Linux ensures smooth server management and troubleshooting.

A hostname makes it easier to recognize different servers and services, improving network organization. We’ll walk you through the step-by-step process to Change Hostname in CentOS and Rocky Linux so your system has the right identity. By following these instructions, you’ll gain confidence in managing your Linux system and be ready for more advanced tasks. Let’s dive in and learn how to easily Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux!

Change Hostname in CentOS and Rocky Linux

Introduction to CentOS and Rocky Linux :

CentOS and Rocky Linux are two popular operating systems based on Red Hat Enterprise Linux (RHEL). They are mostly used for servers, businesses, and cloud computing because they are stable, secure, and reliable. If you need an operating system that runs smoothly and gets long-term updates, CentOS and Rocky Linux are great choices.

CentOS :

CentOS (Community Enterprise Operating System) was a free version of RHEL, offering the same features but without any cost. It became one of the most used Linux distributions for servers and business applications because of its strong performance and security.

However, in December 2020, Red Hat changed CentOS into CentOS Stream, which is no longer a stable release but more like a testing version for future RHEL updates. This change left many users looking for a replacement, as they needed a stable and reliable system for their servers.

Rocky Linux :

Rocky Linux was created as a replacement for CentOS, bringing back the same stability and reliability that CentOS used to offer. It was developed by Gregory Kutzer, one of the original creators of CentOS, to provide a free, enterprise-level Linux system just like RHEL.

Since its release, Rocky Linux has quickly become the best choice for users who needed a secure and stable system. It is widely used in businesses, cloud computing, and data centers because it gets regular updates and long-term support.

Why is Changing the Hostname Important?

The hostname is the unique name of your computer or server on a network. Changing it is important for better identification, management, and communication between systems. A properly set hostname makes it easier to organize servers, troubleshoot issues, and improve security. Here’s why you should change the hostname in CentOS and Rocky Linux:

Why is Changing the Hostname Important?
  • Easy Server Identification – A unique hostname helps you quickly recognize each system, especially if you manage multiple servers. Instead of a generic name like localhost.localdomain, setting a meaningful hostname like web-server or database-server makes it clear what each machine is used for.
  • Better Network Communication – A correct hostname allows computers to connect and communicate more easily. When using SSH, remote access, or file sharing, having a proper hostname instead of relying on IP addresses makes networking more efficient.
  • Improved System Management – For system administrators, managing and troubleshooting servers becomes easier with the right hostname. When checking logs, running commands, or tracking performance, a meaningful hostname helps avoid confusion.
  • Security & Compliance – Many businesses have security policies that require proper hostnames for tracking and auditing. A well-named server ensures better monitoring, security enforcement, and compliance with IT policies.
  • Customization & Branding – If you’re using CentOS or Rocky Linux for a company, setting a hostname that follows your naming convention or organizational structure ensures consistency and professionalism.

Prerequisites to Change Hostname in CentOS and Rocky Linux :

Before you Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux, there are a few things you need to have in place:

Prerequisites to Change Hostname in CentOS and Rocky Linux
  • Root or Sudo Access – You need to have root access or be a user with sudo privileges. This is important because changing the hostname requires special permissions.
  • Terminal Access – To Set Hostname in CentOS and Rocky Linux, you must be able to access the terminal on your system. If you’re working remotely, you’ll need an SSH connection to the server.
  • hostnamectl Command – The hostnamectl command is the easiest way to Change Hostname in CentOS and Rocky Linux. It comes pre-installed on most systems, but if it’s missing, you might need to update your system.
  • Correct Hostname Format – When you Set Hostname in CentOS and Rocky Linux, make sure the new name follows the rules:
    • It should be short, clear, and easy to recognize (like web-server or db-server).
    • Use only letters, numbers, and hyphens.
    • Avoid spaces or special symbols.
  • Network & DNS Considerations – If your machine is part of a network or domain, make sure the new hostname is added to your DNS records to avoid connection problems.

To Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux, make sure you have root or sudo access, terminal access, and the right format for your hostname. Once you’ve got everything ready, you can easily proceed with updating your system’s identity!

Methods to Set or Change Hostname in CentOS and Rocky Linux :

There are different ways to Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux. Below, we’ll walk you through the most common methods:

Set Hostname in CentOS and Rocky Linux

Using hostnamectl Command :

The hostnamectl command is the easiest and most efficient way to Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux. This command is part of the systemd package and allows you to manage system hostnames with ease. Here’s how to use it:

Steps to Set or Change Hostname in CentOS and Rocky Linux Using hostnamectl:

  • Open the Terminal :
    • First, open your terminal on your CentOS or Rocky Linux system. If you’re working remotely, connect via SSH.
  • Use the hostnamectl Command
    • Run the following command to Set or Change Hostname in CentOS and Rocky Linux:
      • sudo hostnamectl set-hostname new-hostname
    • Replace new-hostname with the desired name for your system. For example, if you want to set the hostname to web-server, the command would be:
      • sudo hostnamectl set-hostname web-server
  • Verify the Change :
    • After running the command, you can verify that the hostname has been successfully changed by using:
      • hostnamectl
    • This will show you the current hostname and other related information.

The hostnamectl command is the most straightforward and recommended method to Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux. It’s quick, simple, and doesn’t require manual file editing. Just use the command with sudo privileges and you’re good to go!

Editing the /etc/hostname File :

Another way to Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux is by manually editing the /etc/hostname file. This method is a bit more direct but still effective. Here’s how you can do it:

Steps to Edit the /etc/hostname File:

  1. Open the Terminal :
    • Open a terminal window on your CentOS or Rocky Linux system. If you’re working remotely, connect via SSH.
  2. Edit the /etc/hostname File :
    • You need to open the /etc/hostname file using a text editor. Here, we’ll use nano, but you can use any text editor you’re comfortable with, such as vim or vi. Run the following command to edit the file:
      • sudo nano /etc/hostname
  3. Change the Hostname :
    • Inside the file, you’ll see the current hostname (e.g., localhost.localdomain). Replace this with your new desired hostname. For example, change it to web-server or any name that suits your system:
      • web-server
  4. Save the File :
    • After changing the hostname, save the file:
    • In nano, press Ctrl + X to exit.
    • Then press Y to confirm saving the changes, followed by Enter to save the file.
  5. Edit the /etc/hosts File (Optional but Recommended) :
    • To avoid any issues with networking or local resolution, it’s a good idea to update the /etc/hosts file with your new hostname:
    • Open the /etc/hosts file using a text editor:
      • sudo nano /etc/hosts
    • Find the line that starts with 127.0.0.1 (localhost) and replace the old hostname with the new one. For example:
      • 127.0.0.1 web-server
    • Save the file and exit the editor.
  6. Reboot the System :
    • After editing the files, you need to reboot the system for the changes to take effect.

Editing the /etc/hostname file is an effective way to Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux. While it’s a bit more manual than using hostnamectl, it still works well for those who prefer direct file editing. Just remember to also update the /etc/hosts file and reboot for the changes to apply successfully.

Using the nmcli Command :

If you’re using Network Manager on your CentOS or Rocky Linux system, you can also use the nmcli command to Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux. This method is useful if Network Manager is managing your network settings.

Steps to Set or Change Hostname Using nmcli:

  1. Open the Terminal :
    • Open the terminal on your CentOS or Rocky Linux system. If you’re working remotely, connect via SSH.
  2. Use the nmcli Command :
    • Run the following command to Set or Change Hostname in CentOS and Rocky Linux:
      • sudo nmcli general hostname new-hostname
    • Replace new-hostname with the desired hostname for your system. For example, if you want to set the hostname to web-server, you’d run:
      • sudo nmcli general hostname web-server
  3. Verify the Change :
    • After running the command, you can verify the new hostname by checking the system’s current hostname:
      • hostname
    • This will show the updated hostname.

Using the nmcli command is another simple and effective way to Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux when you’re using NetworkManager. Just run the command with sudo privileges, and you can quickly update your system’s hostname without needing to manually edit configuration files.

Conclusion: Keeping Your System Organized with Proper Hostnames

In this guide, we’ve shown you several ways to Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux. Whether you prefer using the hostnamectl command, editing the /etc/hostname file, or using the nmcli command, it’s easy to update your system’s hostname and ensure your server is properly identified.

Having a clear and meaningful hostname is essential for efficient server management, network communication, and troubleshooting. By knowing how to Set Hostname in CentOS and Rocky Linux, you can easily manage your systems and avoid confusion, especially if you are running multiple servers. Similarly, changing the hostname in CentOS and Rocky Linux can help improve security, network organization, and compliance with IT policies.

No matter your experience level, the steps to Set Hostname in CentOS and Rocky Linux or Change Hostname in CentOS and Rocky Linux are simple and can be done in just a few commands. A well-set hostname ensures that your server environment is organized, making it easier to manage, troubleshoot, and maintain.

Remember to follow the steps carefully, verify your changes, and reboot your system when needed. With the right hostname, you’ll be able to manage your CentOS or Rocky Linux system with ease and confidence.

Checkout Easy 4 Ways to Check CentOS Version Using Linux Commands


Discover more from Owrbit

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply