How to Change Hostname in Rocky Linux 8
Displaying the Current Hostname
To find out your current system name by running the following command.
hostnamectl
Output:
[root@server ~]# hostnamectl
Static hostname: localhost.localdomain
Transient hostname: server
Icon name: computer-vm
Chassis: vm
Machine ID: 2836dc6f733240a0a7678564f019735c
Boot ID: 75bca30024ca42059ff73e898416924e
Virtualization: kvm
Operating System: Rocky Linux 8.3
CPE OS Name: cpe:/o:rocky:rocky:8
Kernel: Linux 4.18.0-240.22.1.el8.x86_64
Architecture: x86-64
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@vps ~]# 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
Alternatively, you can set or change the hostname of your system by running the following command.
nmtui
Select set system hostname.
Set your 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.
Output:
[root@server ~]# hostnamectl
Static hostname: crowncloud.net
Pretty hostname: crowncloud production server
Icon name: computer-vm
Chassis: vm
Machine ID: 2836dc6f733240a0a7678564f019735c
Boot ID: 75bca30024ca42059ff73e898416924e
Virtualization: kvm
Operating System: Rocky Linux 8.3
CPE OS Name: cpe:/o:rocky:rocky:8
Kernel: Linux 4.18.0-240.22.1.el8.x86_64
Architecture: x86-64