How to change the Hostname on CentOS 8

The easiest way to change the hostname on CentOS 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:

[[email protected] ~]# 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:

[[email protected] ~]# hostname
server2.example.com
[[email protected] ~]# 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:

[[email protected] ~]# 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

*