How to Change Hostname in CentOS/RHEL 8

Take Your Linux Skills to the Next Level All courses, certifications, ad-free articles & community — from $8/mo
Join Root →
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Access to Linux certifications (RHCSA, RHCE, LFCS and LFCA)
Access new courses on release
Get access to weekly newsletter
Priority help in comments
Private Telegram community
Connect with the Linux community
From $8/mo · or $59/yr billed annually · Cancel anytime

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.

127.0.0.1	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.

Root Plan
Premium Linux Education for Serious Learners

Take Your Linux Skills to the Next Level

Root members get full access to every course, certification prep track, and a growing library of hands-on Linux content — with new courses added every month.

What You Get
Ad-free access to all premium articles
Access to all courses: Learn Linux, AI for Linux, Bash Scripting, Ubuntu Handbook, Golang and more.
Access to Linux certifications (RHCSA, RHCE, LFCS and LFCA)
Access new courses on release
Get access to weekly newsletter
Priority help in comments
Private Telegram community
Connect with the Linux community
Ravi Saive
I'm Ravi Saive, an award-winning entrepreneur and founder of several successful 5-figure online businesses, including TecMint.com, GeeksMint.com, UbuntuMint.com, and the premium learning hub Pro.Tecmint.com.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.