How to Change Hostname in Rocky Linux 9
Displaying the Current Hostname
Find out the hostname of your system by using the below command,
hostnamectl
Output:
[root@server ~]# hostnamectl
Static hostname: n/a
Transient hostname: server
Icon name: computer-vm
Chassis: vm
Machine ID: 20b5506b9d87493f872d80205d51b9cc
Boot ID: 5d8f3e5d6a104727ae51be1fab078e0c
Virtualization: kvm
Operating System: Rocky Linux 9.0 (Blue Onyx)
CPE OS Name: cpe:/o:rocky:rocky:9::baseos
Kernel: Linux 5.14.0-70.13.1.el9_0.x86_64
Architecture: x86-64
Hardware Vendor: Red Hat
Hardware Model: KVM
Changing the System Hostname
Now that you know the current hostname, you can change the hostname by using the following command, and Optionally you can also set the pretty hostname as follows.
hostnamectl set-hostname crowncloud.net
hostnamectl set-hostname "crowncloud production server" --pretty
Next, add the record for the hostname in the /etc/hosts
file.
127.0.0.1 crowncloud.net
Edit the file using your favorite editor.
nano /etc/hosts
After you've added/edited the file, save and exit the file.
Output:
[root@server ~]# cat /etc/hosts
127.0.0.1 crowncloud.net
This will also add an entry to the /etc/hostname
file automatically.
Restart the systemd-hostnamed
service.
systemctl restart systemd-hostnamed
Alternatively Set or Change Hostname using NMTUI
Alternatively, you can set or change the hostname of your system using NetworkManager's Text User Interface. Run the following command and follow the steps as shown below,
nmtui
Select set system hostname.
Enter the new hostname.
Restart the systemd-hostnamed
service.
systemctl restart systemd-hostnamed
Verify the Change
To verify the hostname has been fully changed, enter the hostnamectl
command.
[root@server ~]# hostnamectl
Static hostname: crowncloud.net
Pretty hostname: crowncloud production server
Icon name: computer-vm
Chassis: vm
Machine ID: 20b5506b9d87493f872d80205d51b9cc
Boot ID: 5d8f3e5d6a104727ae51be1fab078e0c
Virtualization: kvm
Operating System: Rocky Linux 9.0 (Blue Onyx)
CPE OS Name: cpe:/o:rocky:rocky:9::baseos
Kernel: Linux 5.14.0-70.13.1.el9_0.x86_64
Architecture: x86-64
Hardware Vendor: Red Hat
Hardware Model: KVM