This tutorial guides you through the process of change a hostname on a CentOS 8 system.
The hostname is set at the time when the CentOS operating system is installed or if you are spinning up a virtual machine it is dynamically assigned to the instance at startup.
This tutorial helps you to change a hostname on a CentOS 8 system.
Before starting, make sure you are logged in with non-root user with sudo privileges.
Change Hostname on CentOS
By assigning a hostname you can identify a system on a network. It is important that you shouldn’t have same hostname on a same network.
There are three types of hostnames as below:
- static – This is the most important type of hostname. This is used to identify a particular server between machines on network. It’s stored at
/etc/hostnamefile. For example, TecNStuff’s Server.
- pretty – This is more user-friendly and can use more characters and punctuation as per UTF8 character set. It represents the user. For example
- transient – A transient hostname is changed in the Linux kernel. It is the same as the static hostname. Transient hostnames can be set/update by DHCP or mDNS at runtime.
It is best practice to use a fully-qualified domain name (FQDN) for both
transient hostnames like
Check Existing Hostname
Run below command to check the existing hostname for your system:
Static hostname: localhost.tecnstuff Icon name: computer-vm Chassis: vm Machine ID: 31dcdc11e56e403c8053ecdf0b92d452 Boot ID: e289757e3c8145e09eb4d55172189a14 Virtualization: kvm Operating System: CentOS Linux 8 (Core) CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 4.18.0-80.7.1.el8_0.x86_64 Architecture: x86-64
As you can see on above output, here current hostname name is
Change the Hostname using hostnamectl
In CentOS 8 system, we can use
hostnamectl command to change the hostname and related settings. Following is the basic syntax to change hostname:
sudo hostnamectl set-hostname NEW_HOST_NAME
sudo hostnamectl set-hostname server.yourdomain.com
sudo hostnamectl set-hostname server.yourdomain.com --static
sudo hostnamectl set-hostname "Pretty HostName" --pretty
sudo hostnamectl set-hostname server.yourdomain.com --transient
You can run command as below to change hostname:
sudo hostnamectl set-hostname server.tecnstuff.net
Here we changed hostname from
hostnamectl command. Now the hostname is
server.tecnstuff.net for server, you can check it again using
Same as you can set pretty name for server using below command:
sudo hostnamectl set-hostname "TecNStuff's Server" --pretty
To verify that the hostname changed successfully, use
hostnamectl command and now it should show output with new hostname as below:
Static hostname: server.tecnstuff.net Pretty hostname: TecNStuff's Server Icon name: computer-vm Chassis: vm Machine ID: 31dcdc11e56e403c8053ecdf0b92d452 Boot ID: e289757e3c8145e09eb4d55172189a14 Virtualization: kvm Operating System: CentOS Linux 8 (Core) CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 4.18.0-80.7.1.el8_0.x86_64 Architecture: x86-64
As you can see above the hostname is successfully changed from
server.tecnstuff.net and also Pretty hostname is
On CentOS system, you can can use the hostnamectl command to change hostname and set a new name as well.
If you face any issues you can leave a comment below.