Search

How to change hostname in rocky linux 9

How to Change Hostname in Rocky Linux 9

Changing the hostname in Rocky Linux 9 is a straightforward process. Whether you want to set a new hostname temporarily or permanently, this guide will walk you through the necessary steps.

Step 1: Check the Current Hostname

Before making any changes, let's see the current hostname of your system. Open a terminal and type the following command:

hostnamectl status

This command will display the current hostname along with other system details.

Step 2: Change the Hostname Temporarily

If you wish to change the hostname temporarily (until the next reboot), you can use the hostname command:

sudo hostname new-hostname

Replace new-hostname with your desired hostname. Note that this change will only last until the system is rebooted.

Warning: Temporary hostname changes will be lost after a reboot. To make the change permanent, proceed to the next step.

Step 3: Change the Hostname Permanently

To change the hostname permanently, you'll need to use the hostnamectl command:

sudo hostnamectl set-hostname new-hostname

Again, replace new-hostname with your desired hostname. This change will persist across reboots.

Step 4: Update the /etc/hosts File

It's also a good practice to update the /etc/hosts file to reflect the new hostname. Open the file in your favorite text editor:

sudo nano /etc/hosts

Find the line that looks like this:

127.0.0.1   localhost localhost.localdomain

And add a new line with your new hostname:

127.0.0.1   new-hostname

Save the changes and exit the editor (in nano, you can do this by pressing Ctrl + X, then Y, and finally Enter).

Step 5: Verify the Change

Finally, verify that the hostname has been changed successfully:

hostnamectl status

You should see your new hostname listed in the output.

Success: Your hostname has been updated successfully!

Conclusion

By following these steps, you can easily change the hostname on your Rocky Linux 9 system. Remember to update the /etc/hosts file to ensure network applications and services continue to function correctly with the new hostname. If you encounter any issues, feel free to leave a comment for further assistance.

Sys Admin

Sys Admin

I am a Red Hat Certified Engineer (RHCE) and working as an IT Professional since 2012...