How to Change Hostname on RHEL 9 (Red Hat Enterprise Linux 9)
Last Updated :
29 Feb, 2024
Changing the hostname on RHEL 9 (Red Hat Enterprise Linux 9) is a fundamental task that can be accomplished with a few simple steps. In this detailed guide, we will walk you through each aspect of the process, ensuring that even beginners can understand and execute the procedure successfully.
Step 1: Check the Current Hostname
Before making any changes, it's important to know the current hostname of your system. This can be done using the `hostnamectl` command. Open a terminal and type:
hostnamectl
checking hostname in rhel9This command will display information about your system's current hostname and other related settings.
Step 2: Change the Hostname
To change the hostname on RHEL 9, you need to edit the `/etc/hostname` file. This file contains the current hostname of your system. Open a terminal and use a text editor (e.g.,` nano`, `vi`, `gedit`) to edit the file:
sudo vi /etc/hostname
Replace the existing hostname with the new hostname you want to use. Make sure the new hostname follows the hostname conventions (e.g., no spaces or special characters). Save the file and exit the text editor.
changing hostname in rhel9Step 3: Update the Hosts File
Next, you need to update the `/etc/hosts` file to reflect the new hostname. This file maps IP addresses to hostnames and is used by the system for hostname resolution. Open the file in a text editor:
sudo vi /etc/hosts
Find the line that starts with `127.0.0.1` (localhost) and update it to include your new hostname. For example:
127.0.0.1 localhost localhost.localdomain your-new-hostname
Replace `your-new-hostname` with the new hostname you've chosen. Save the file and exit the text editor.
Step 4: Apply the Changes
To apply the new hostname, you can either restart your system or use the hostnamectl command:
sudo hostnamectl set-hostname your-new-hostname
Replace `your-new-hostname` with the new hostname you've chosen. After running this command, you may need to log out and log back in for the changes to take effect.
Step 5: Verify the Changes
To verify that the hostname has been changed successfully, you can use the hostnamectl command again:
hostnamectl
verifying the hostname in rhel9This command should display the new hostname you've set.
Conclusion
In conclusion, changing the hostname on RHEL 9 is a straightforward process that can be accomplished by following a few simple steps. By checking the current hostname, editing the /etc/hostname and /etc/hosts files, applying the changes using hostnamectl, and verifying the new hostname, even beginners can successfully change the hostname on their system. Additionally, common questions regarding changing the hostname, such as the impact on network services and applications, the rules for choosing a hostname, and the ability to revert to the previous hostname, are addressed to provide a comprehensive understanding of the topi
Explore
Getting Started with Linux
Installation with Linux
Linux Commands
Linux File System
Linux Kernel
Linux Networking Tools
Linux Process
Linux Firewall
Shell Scripting & Bash Scripting
Linux Administrator System