How to change the Hostname on AlmaLinux 8, CentOS 8 and Rocky Linux 8

Last Updated on May 8, 2022 by admin

Change Hostname

The easiest way to change the hostname on AlmaLinux 8, CentOS 8, and Rocky Linux 8 is to use the hostnamectl command.

First I will check the current hostname by running "hostnamectl status" on the shell of my server:

hostnamectl status

The output on my system is:

[root@server1 ~]# hostnamectl status
Static hostname: server1.example.com
Icon name: computer-vm
Chassis: vm
Machine ID: 96fe4cd6012b4aaba591aafa777f34ce
Boot ID: 65e2a77597d743eeb35e25b6bec7fe9f
Virtualization: vmware
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-193.19.1.el8_2.x86_64
Architecture: x86-64

Then I change the hostname with the set-hostname option of the hostnamectl command to server2.example.com

hostnamectl set-hostname server2.example.com

Afterward, I check with the command hostname and hostname -f if the hostname change has succeeded.

hostname
hostname -f

The result should be:

[root@server1 ~]# hostname
server2.example.com
[root@server1 ~]# hostname -f
server2.example.com

Instead of the hostname command, you could also use the "hostnamectl status" command again to check if the new hostname has been set:

[root@server1 ~]# hostnamectl status
Static hostname: server2.example.com
Icon name: computer-vm
Chassis: vm
Machine ID: 96fe4cd6012b4aaba591aafa777f34ce
Boot ID: 65e2a77597d743eeb35e25b6bec7fe9f
Virtualization: vmware
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-193.19.1.el8_2.x86_64
Architecture: x86-64

Leave a Comment