How to change the Hostname on CentOS

Changing the hostname of your CentOS PC is one of the routine tasks. Let's look at how to change the hostname on a local CentOS system or a remote machine connected over a network.

The hostname is a critical piece of information that helps you maintain your server machines. As a system administrator, it is imperative to have a short but recognizable hostname to separate the server machines from each other. An ambiguous or complex hostname may cause difficulty in recognizing the exact server that you may want to access remotely and can increase chances of error while applying software patches or other updates.

In this article, I’ll focus on changing the CentOS server’s Hostname, but before that, let’s discuss the different types of Hostname.

Hostname has three types:

Static Hostname: It is the primary and essential Hostname. They are kept in the /etc/hostname file. It is used by machines to recognize the specific server.

Pretty Hostname: This hostname type is user friendly. It allows you to use additional character and punctuation. But it is not permitted for machine code due to its non-standard characters.

Transient Hostname: It is a temporary hostname and is reset after the reboot. Linux Kernel maintains this Hostname. You can use it for a minor troubleshooting job in a session.

In this article, we will describe a method to change it permanently without restarting your PC.

How to change the Hostname on CentOS

To change the Hostname in the CentOS permanently follow the beneath steps:

Step 1: Check Current Hostname

Firstly, you should know the current Hostname. To check the current Hostname, type hostnamectl command in the console.

$ hostnamectl

This command will list the operating system and network configuration information along with the static Hostname.


Static hostname: workmachine21
Icon name: computer-desktop
Chassis: desktop
Machine ID: 5f7e36c18a974f06ae94ddaaf11d71e8
Boot ID: 337e48b00fed4abe9ab929fed5aa6018
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-193.x86_64
Architecture: x86-64

Step 2: Change the Static Hostname

Before changing the static Hostname of CentOS 7, you should know the values of it because it allows only Fully Qualified Domain Names (FQDNs).

It includes:

  • Lower-case letters A-Z
  • Numbers 0-9
  • Hyphens and Periods
  • Character limit of the Hostname is 2 to 63
  • Hostname start and end must be a letter or a number.

Now type the command as follows:

hostnamectl set-hostname fosslinux

We just changed the static Hostname from “workmachine” to “fosslinux”.

Step 3: Verify the Hostname

After changing the Hostname, verify it by typing the hostnamectl command. The result shows the system information along with a new static hostname.


Static hostname: fosslinux
Icon name: computer-desktop
Chassis: desktop
Machine ID: 5f7e36c18a974f06ae94ddaaf11d71e8
Boot ID: 337e48b00fed4abe9ab929fed5aa6018
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-193.x86_64
Architecture: x86-64

Step 4: Use Pretty and Transient Hostname (Optional)

For setting a pretty Hostname, the use of quotation marks is mandatory if the Hostname contains spaces or a single quotation mark. For example:

hostnamectl set-hostname "FOSS Linux" --pretty

For Transient Hostname, where we set a temporary hostname, use the command below:

sudo hostnamectl –transient set-hostname temporary.fosslinux

After completing the renaming, check the status of Hostname by using the command:

hostnamectl status

The console will return a list of information, including the static, pretty, and transient Hostname, to confirm the change.

Note: Machines can only identify the FQDN hostname. So, CentOS automatically changes or removes the unacceptable characters.

Clearing a Particular Host Name

To clear a hostname and revert to the default, enter the following command as root with the appropriate option:

hostnamectl set-hostname "" [option...]

Where “” is a quoted empty string followed by option is one or more of: –pretty, –static, and –transient.

Changing Host Names Remotely

For the situations where you want to execute a hostnamectl command on a remote system, use the -H, –host option as follows:

hostnamectl set-hostname -H [username]@name

The tool will use SSH to connect to the remote system. Where name is the remote Hostname, you want to configure. The username is optional.


That’s all about setting, clearing the CentOS hostname on a local machine or over the network, remotely. Run the desired command from the commands as mentioned earlier and permanently or temporarily change the Hostname.

Habib Ahmed
He is a professional writer with more than seven years of experience in the field. He also enjoys technical writing/ manuals, white papers, and scientific presentations.


Please enter your comment!
Please enter your name here





The year is 2020, and Linux-based operating systems have never been more popular. All thanks to their increased security and privacy, smooth updates, and open-source nature, everyone wants to at least give a shot to its multitude of distributions. Now we have already covered some of the best Linux-based laptops that you can find in the market as of now. With that being said, we get it that they are not everyone's cup of tea, so Linux PC desktops are also something that you should be taking a look at as well.
“I am because you are,” is the themed meaning behind the famed Ubuntu operating system. Moreover, this mindful phrase is practical because it continues to lure more individuals into the Ubuntu universe. Because great power beckons great responsibility, Ubuntu is stepping up. It realizes that different users will want to use the Ubuntu operating system software differently.

Linux vs. BSD: 10 Key Things You Need to Know

Both Linux and BSD (Berkeley Software Distribution) are free, open-source, and based on Unix. Both systems also use many of the same applications and strive towards the same goal - developing the most stable and reliable operating system.

Top 5 Linux Distros for Windows Users

When Microsoft initially released Windows 7 in October 2009, the software giant committed to providing ten years of support for its popular operating system.  The much-maligned Microsoft was true to their word, support for Windows 7 ended just yesterday a little over ten years after its release.

10 Best Video Editing Software for Linux

This article is for all the Linux users out there who are looking for video editors to create their own professional videos, which can range from short documentaries to even movies.

Ubuntu Cinnamon Remix Review

The Ubuntu Cinnamon Remix brings together Linux Mint's Cinnamon desktop with the Ubuntu Core. While some users are welcoming the new flavor of Ubuntu with open arms, others are scratching their heads, wondering where it fits in.