[email protected]Office hours: Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
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 Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

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

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

Get Started →Contact Us
[email protected]Office hours: Mon – Fri 9:00AM – 5:00PM