How to Change Hostname on CentOS 8

Change Hostname on CentOS 8

In this article, we will have explained the necessary steps to change hostname on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

A hostname is a name assigned to a “host” i.e. a computer on a network. The hostname is basically just your computer’s name. It’s used to identify your computer on the network.

There are three classes of hostname: static, pretty, and transient.

  • static – The traditional hostname. It is stored in the /etc/hostname file and can be set by the user.
  • pretty – A free-form UTF8 hostname used for presentation to the user. For example, linuxtips's desktop.
  • transient – A dynamic hostname that is maintained by the kernel. DHCP or mDNS servers can change the transient hostname at run time. By default, it is the same as the static hostname.

Change Hostname on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

Step 2. Change hostname in CentOS using command line.

  • To set a persistent hostname using hostnamectl command, use the command:


Confirm your new hostname:

  • Set Pretty hostname.

  • Set Transient hostname – Usually same as static hostname.

To view the current hostname, execute the following command:

Congratulation, you have learned how to change hostname on CentOS 8. If you have any question, please leave a comment below.