How to Change Hostname in CentOS/RHEL 8

Setting up a hostname is one of the quintessential tasks when setting up a server. A hostname is a name that is assigned to a PC in a network and helps in uniquely identifying it.

There are various ways of setting up a hostname in CentOS/RHEL 8 and we are going to look at each in turn.

To display the system’s hostname, run the command.

$ hostname
Check RHEL 8 Hostname

Check RHEL 8 Hostname

Additionally, you can execute the hostnamectl command as shown:

$ hostnamectl
Check System Hostname

Check System Hostname

Setting a Hostname in RHEL 8

To configure a hostname, login and use the hostnamectl command as shown:

$ sudo hostnamectl set-hostname 

For example, to set the hostname to tecmint.rhel8 execute the command:

$ sudo hostnamectl set-hostname tecmint.rhel8
Set System Hostname

Set System Hostname

You can later verify if the new hostname has been applied to your system by running the hostname or hostnamectl commands.

$ hostname
$ hostnamectl
Confirm System Hostname

Confirm System Hostname

Next, add the record for the hostname in the /etc/hosts file.	tecmint.rhel8

This automatically adds an entry by default to the /etc/hostname file.

Save and exit the text editor.

Finally, restart the networking service for the changes to come into effect.

$ sudo systemctl restart NetworkManager

Alternatively, you can use nmtui command to set or change the hostname of your system as shown.

$ sudo nmtui
Set System Hostname

Set System Hostname

Enter your new hostname.

Add New Hostname

Add New Hostname

Finally, restart the systemd-hostnamed service to apply recent changes.

$ sudo systemctl restart systemd-hostnamed

And this concludes this guide on how to change or set a hostname on CentOS/RHEL 8. We hope you found this guide helpful.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Ravi Saive

I am Ravi Saive, creator of TecMint. A Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux. Follow Me: Twitter, Facebook and Google+

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide
The Complete Linux System Administrator Bundle
Become an Ethical Hacker Bonus Bundle

You may also like...

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.