[email protected]Support 24/7 · Billing 09:00 – 00:00LinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedSeptember 11, 2023

How to Change Hostname on CentOS 8.

How To Change Hostname On CentOS 8.

This guide explains how to set or change the hostname on CentOS 8 without needing to restart the system.

There are a number of reasons why you may need to change the hostname. The most common is when the hostname is automatically set upon the instance creation.

 

Understanding Host Names

A hostname is a label that identifies a device on a network. You shouldn’t have two or more machines with the same hostname, on the same network.

There are three classes of hostname: static, pretty, and transient.

  • static – The traditional hostname. It is stored in the /etc/hostname file and can be set by the user.

  • pretty – A free-form UTF8 hostname used for presentation to the user. For example, nexonhost desktop.

  • transient – A dynamic hostname that is maintained by the kernel. DHCP or mDNS servers can change the transient hostname at run time. By default, it is the same as the static hostname.

It is recommended to use a fully-qualified domain name (FQDN ) for both static and transient names such as host.example.com.

 

Displaying the Current Hostname

To view the current hostname, execute the following command:

hostnamectl

In this example, the current hostname is set to centos8.localdomain.

 

Changing the Hostname

 

Method 1: Using the hostnamectl command

In CentOS 8 and all other Linux distributions that are using systemd, you can change the system hostname and related settings with the hostnamectl command. The syntax is as follows:

sudo hostnamectl set-hostname host.example.com
sudo hostnamectl set-hostname "Your HostName" --pretty
sudo hostnamectl set-hostname host.example.com --static
sudo hostnamectl set-hostname host.example.com --transient

For example, to change the system static hostname to host.nexonhost.com, you would use the following command:

sudo hostnamectl set-hostname host.nexonhost.com

To set the pretty hostname to nexonhost’s desktop, enter:

sudo hostnamectl set-hostname "nexonhost's desktop" --pretty

The hostnamectl command does not produce output. On success, 0 is returned, a non-zero failure code otherwise.

To verify that the hostname was successfully changed, use the hostnamectl command.

 

Method 2: Using the nmtui command

nmtui is a curses-based tool for interacting with NetworkManager. It can also be used to set or change the hostname.

Launch the tool by typing its name in the terminal:

sudo nmtui

Use the arrow keys to navigate through the options, select Set system hostname and press Enter.

Type the new hostname:

Press Enter to confirm the new hostname:

Finally, restart the systemd-hostnamed service for the changes to take effect:

sudo systemctl restart systemd-hostnamed

 

Method 3: Using the nmcli command

nmcli is a command-line tool for controlling the NetworkManager and can also be used to change the system’s hostname.

To view the current hostname, type:

sudo nmcli g hostname

To change the hostname to host.nexonhost.com use the following command:

sudo nmcli g hostname host.nexonhost.com

For the changes to take effect, restart the systemd-hostnamed service:

sudo systemctl restart systemd-hostnamed

 

Conclusion

To set or change the hostname on CentOS system, use the hostnamectl set-hostname command followed by the new hostname.

Keep reading
How to use man command in Linux.
September 13, 2023

How to use man command in Linux.

How To Use Man Command. The man command is a built-in manual for using Linux commands. It allows users to view the reference manuals of a command or utility run in the terminal. The man page (short for manual page) includes a command description, applicable options, flags, examples, and other…

Read article
How to use unalias command in Linux.
September 13, 2023

How to use unalias command in Linux.

How To Use Unalias Command. The unalias command is a Unix and Unix-like operating system command used to remove or unset aliases in a shell session. In Unix-based systems, aliases are shortcuts or user-defined commands that allow you to create shorter or more convenient names for longer or…

Read article
How to use alias command in Linux.
September 13, 2023

How to use alias command in Linux.

How To Use Alias Command. Depending on the type of work you do on your Linux system, you may need to enter the same long and complicated commands frequently. The alias command lets you create shortcuts for these commands, making them easier to remember and use. In Linux, an alias is a shortcut…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, cloud hosting, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Support 24/7 · Billing 09:00 – 00:00