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





Buyers who wish to go for a machine that is based on Linux often show interest in Chromebooks due to the form factor and extended battery life capabilities. Although ChromeOS power these machines, users can still miss out on a more genuine Linux experience. For those who happen to agree, the new Lemur Pro by System76 might get some heads turning.
Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.

5 ways to send emails using the command-line in Linux

Did you master using the command-line in Linux? There is no limit to what one can do via the Linux Terminal. One of such things we are going to discuss today are methods of sending an email using the command-line.

10 Best PDF Editors for Linux

In this article, we will take a look at 10 of the best PDF editors and tools out there in 2019 that are available for Linux platforms. The editors are going to be judged on the basis of their functionalities, portability, ease of installation, price, and convenience.

Ubuntu 19.10 (Eoan Ermine) Beta Installation and Overview

It may be early, but I've been looking forward to the release of Ubuntu 19.10 for some time now. As an impatient person, and promised readers in the FOSSLinux article announcing the release of Eoan Ermine that we would provide you a review of Ubuntu 19.10 Eoan Ermine - Beta.  So, here it goes.

The 10 Best Linux Server Distros For Home And Businesses

By the year 2020, it is estimated that there are close to 600 Linux distributions in the market. It includes both servers and Desktop versions; therefore, if you are looking for lightweight Linux distribution for your old PC or a reliable desktop version for employees in your organization, you may be overwhelmed with the number of choices for finding one for your use.