How to Set and Change Hostname in Rocky Linux
When working in the local environment, each system is assigned an IP address to distinguish them from one another on the LAN. However, it is very difficult to remember each host by their IP address, especially in a large environment. In this case, we can assign a unique hostname to each machine to remember them easily. Hostname also allows each machine to communicate using the device name rather than the IP address.
This post will show you how to set and change the hostname in Rocky Linux. This procedure is compatible with Rocky Linux 8 and Rocky Linux 9.
In This Article
- Check Your Current Hostname
- Change the Hostname Temporarily
- Change the Hostname Permanently
- Change the Hostname Using /etc/hostname File
- Change the Hostname Using NMTUI Tool
Step 1 – Check Your Current Hostname
Before setting up a hostname, it is important to check the current hostname of your system.
You can check it using the following command:
You should see the current hostname of your system in the following output:
Static hostname: vyompc Icon name: computer-laptop Chassis: laptop Machine ID: cfefe3a7c8694e51879fb521a2021b2e Boot ID: ef565102d26f4edfb9cadd816eb99419 Operating System: Rocky Linux 8.4 ( Green Obsidian ) Kernel: Linux 5.4.0-99-generic Architecture: x86-64
As you can see, the current hostname of your system is vyompc.
Step 2 – Change the Hostname Temporarily
If you want to change the hostname of your system temporarily, you can use the following syntax:
After a system restart or logging out, the set hostname will return to the previous one.
For example, to change the hostname to newpc, run the following command:
Step 3 – Change the Hostname Permanently
You can use the hostnamectl command to change your system hostname permanently. Use the following syntax to change the hostname permanently:
hostnamectl set-hostname new-hostname
For example, to change the hostname of your system to newpc, run the following command:
hostnamectl set-hostname newpc
After running the above command, you can confirm the new hostname using the following command:
Step 4 – Change the Hostname Using /etc/hostname File
You can also change the hostname by editing the hostname configuration file. In this case, you will need to restart your system to apply the changes.
To change the hostname, edit the /etc/hostname file:
Replace the old hostname with a new hostname:
Save and close the file, then restart your system to apply the changes:
Step 5 – Change the Hostname Using NMTUI Tool
You can also change the system hostname using the NMTUI tool.
To change the system hostname, open the command line interface and run the following command:
You should see the following dialog box:
Select Set system hostname and press the Enter key. You should see the following dialog box:
Type your new hostname and click on the OK. You should see the following dialog box:
Click on the OK button to change the hostname.
In this guide, we explained several methods to change the hostname of your Rocky Linux 8. You can now use your preferred method to change your system hostname. Try it on dedicated hosting from Atlantic.Net!
Get a $250 Credit and Access to Our Free Tier!
Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year