To change the hostname on Rocky Linux 9, follow the steps below.
Step 1 : Check the current hostname using the following command:
Step 2 : Set the new hostname using the following command:
Step 3 : Verify the change by checking the hostname again:
Step 4 : Open the /etc/hosts file to update the new hostname:
In the file, locate the line containing the old hostname and replace it with the new one (e.g., server-01).
Step 5 : Reboot your system for the changes to take effect:
Congratulations, you have successfully set or changed the hostname on Rocky Linux 9.