How to set Hostname in CentOS / Red Hat

Hostname is simple but very important component of every OS. You will use it to identify machine, generate SSL, use services…

Here is quick tutorial how to set username in RHEL 8 

To view current hostname, we will use command hostnamectl

hostnamectl status

We will set hostname with set-hostname command

(change dc.test.local with your values, dc will be name of my machine, and test.local – domain name)

sudo hostnamectl set-hostname dc.test.local

Check hostname by entering hostnamectl

hostnamectl

Name is changed.

You can also set pretty name. It is only presented to you, not used by machine, just so you can better distinguish your machines.

(there are two minuses before pretty word)

sudo hostnamectl set-hostname "Zeljko’s DC" --pretty

Again, check settings with hostnamectl command

hostnamectl

At all times you can clear set hostnames by entering:

sudo hostnamectl set-hostname ""