How to change the hostname on CentOS 8

s2 0

The host name is also known as the computer, device, or domain name that is assigned to a computer when it connects to the Internet. The host name must be unique in the network and is assigned when the operating system is installed. It can also be allocated dynamically when a virtual machine is created.

In CentOS 8 that is hostnamectl and nmcli Commands can be used to change the host name of desktop and server systems. With the Hostname Command you can see the host name of your system.

The domain or host name is usually included in the system startup file (/ etc / hostname). This article will teach you how to change the hostname of your system on CentOS 8 without restarting the computer system.

requirements

Before proceeding, you need to make sure that you are logged in as an administrator account with sudo command permissions.

Understanding of host names

As mentioned above, the host name is a unique label assigned to a system or device that is connected to a network. It must be noted that two or more on the same network do not have a similar host name.

There are three types of host names:

  1. Static
  2. Quite
  3. Transient

Static host name

It is a traditional type of hostname. The static host name is in the / etc / hostname File and can be changed by the user.

Nice hostname

It’s a UTF8 host name and user that will be used for the presentation. For example CentOS-PC.

Temporary host name

It is a dynamic host name managed by the kernel. The static host name and the transient host name are the same by default.

View the current host name

To see the current host name, open the terminal window and run the following command:

$hostnamectl

Another command is used to display the current host name. Enter the following command at the terminal.

$hostname

Here is the host name of my CentOS 8.0 system k8s-master.

Three different commands to change the host name

There are the following methods to change the hostname name on CentOS 8:

The hostnamectl command

The hostnamectl command is used to change the host name on the CentOS 8 Linux system. Run the following command to change the host name:

$ sudo hostnamectl set-hostname {change-name}

the hostnamectl Command does not produce any output. To verify that the host name was changed successfully, run the hostnamectl Command. Here the host name is set as CentOS-PC.

Nmtui command

It is a cursed tool for communicating with NetworkManager. the nmtui Command is also used to change or set the host name.

To start this tool, run the following command on the terminal:

$ sudo nmtui

Once the user interface has started, the arrow keys are used to navigate through all of the options. Select the Set system hostname option and press Enter Key:

nmtui command

Enter the host name you want to assign. Here, hostname CentOS PC, move down and select Opportunity.

Define a new host name

A dialog box would display “Set hostname to CentOS-PC” on the screen. Choose the OK option.

Confirm the new host name

After successfully changing the host name of the system. Now enter the command hostnamectl to check the change of the host name or start the systemd hostname Service for the host name changes to take effect:

$sudo systemctl restart systemd-hostnamed

Restart hostname

The host name was changed successfully.

The nmcli command

It is a command line tool to administer the NetworkManager and nmcli is also used to set the host name of the system.

Enter the following command on the terminal to view the current host name:

$sudo nmcli g hostname

Change the host name using the nmcli online command

Run the following command to change the hostname in CentOS-PC:

$sudo nmcli g hostname CentOS-PC

To verify the system host name change, start the systemd hostname Service:

$sudo systemctl restart systemd-hostnamed

The host name was changed in the system by adding the nmcli Command.

Note: This is the best way to use a fully qualified domain name for both temporary and static names like host.abc.com

diploma

In this tutorial we learned how to change or set the system hostname on CentOS 8. We also examined various commands hostnamectl, nmtui, and nmcli to change the host name. I hope this article has been of great use to you and that you are now able to change your system’s hostname. These commands are recommended for every CentOS user.

How to change the hostname on CentOS 8