How to modify the hostname on CentOS 8

Usually the host name is set during the installation of the operating system or dynamically specified during the creation of the virtual machine.

There are many reasons why you need to change the hostname. The most common reason is that when an instance is automatically created, the host name needs to be automatically set.

This guide explains how to modify the hostname on CentOS 8 without rebooting the system.

1. Prerequisites##

Before proceeding with this article, please make sure you log in to the system with an account with sudo privileges.

Second, understand the host name##

A host name is the label name that marks a device on the network. In the same network, you should not have two or more machines with the same hostname.

` There are three types of hostname: static, pretty, and transient

We strongly recommend using the full domain name (FQDN) to set static and transient names, such as host.example.com.

Three, display the current host name##

Execute the following command to display the current host name.

hostnamectl

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

Fourth, modify the host name##

Method 1: Use the hostnamectl command

In CentOS 8 and all Linux distributions that use systemd, you can use the hostnamectl command to modify the system hostname and related settings. The syntax is as follows:

sudo hostnamectl set-hostname host.example.com
sudo hostnamectl set-hostname "Your Pretty 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 host name to host.linuxize.com, you will use the following command:

sudo hostnamectl set-hostname host.linuxize.com

To change the pretty host name to Linuxize's desktop, enter:

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

The hostnamectl command does not produce output. If successful, return 0, otherwise, return a non-zero error code.

To verify that the host name was successfully modified, use the hostnamectl command.

Method two, use nmtui command

nmtui is a curses-based tool that interacts with the network manager. It can also be used to set or modify the host name.

Start this tool and enter its name in the terminal:

sudo nmtui

Use the arrow keys to move, select Set system hostname, and press the'Enter' key:

Enter the new host name:

Press Enter to confirm the new hostname:

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

sudo systemctl restart systemd-hostnamed

Method three, use nmcli command

nmcli is a command line tool used to control the network manager, and it can also modify the hostname of the system.

To view the current host name, enter:

sudo nmcli g hostname

To change the host name to host.linuxize.com, use the following command:

sudo nmcli g hostname host.linuxize.com

To make the changes take effect, restart the systemd-hostnamed service:

sudo systemctl restart systemd-hostnamed

Five, conclusion##

To modify the hostname of the CentOS system, use the hostnamectl set-hostname command to add the new hostname to modify it.

Recommended Posts

How to modify the hostname on CentOS 8
How to modify the hostname on Ubuntu 20.04
How to modify the CentOS server time to Beijing time
How to install jdk1.8 on centOS7
How to install MySQL on CentOS 8
How to install Memcached on CentOS 8
How to install R on CentOS 8
How to install FFmpeg on CentOS 8
How to install Virtualbox on CentOS 8
How to install TensorFlow on CentOS 8
How to Update to gcc4.9.x on Centos7
How to install TeamViewer on CentOS 8
How to install Perl 5 on CentOS
How to install Git on CentOS 8
How to install Gradle on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Jenkins on CentOS 8
How to install Java on CentOS 8
How to install Go on CentOS 8
How to install GCC on CentOS 8
How to install Yarn on CentOS 8
How to install Asterisk on CentOS 7
How to install Jenkins on CentOS 8
How to install Python 3.8 on CentOS 8
How to install Tomcat 9 on CentOS 8
How to install Webmin on CentOS 8
How to install Ruby on CentOS 8
How to install Skype on CentOS 8
How to install htop on CentOS 8
How to install Python on CentOS 8
How to install Elasticsearch on CentOS 8
How to install Postgresql on CentOS 8
How to install Wordpress on Centos
How to install htop on CentOS 8
How to install TeamViewer on CentOS 8
How to add swap on CentOS 7
How to install MariaDB on CentOS 8
How to install MongoDB on CentOS 7
How to install Odoo 13 on CentOS 8
How to install Apache on CentOS 8
How to disable SELinux on CentOS 8
How to install OpenCV on CentOS 8
How to install PHP on CentOS 8
How to install MongoDB on CentOS 8
Modify CentOS hostname
How to set or modify the time zone on Ubuntu 20.04
How to set or modify the time zone on Ubuntu 20.04
How to set or modify the time zone in CentOS 8
How to increase swap space on CentOS 8
How to install Apache Maven on CentOS 8
How to install Apache Kafka on CentOS 7
R&D: How To Install Python 3 on CentOS 7
How to install GCC compiler on CentOS 7
How to install offline JDK1.8 on centos7.0
How to set up the Nginx server configuration block on CentOS 8
How to change the CentOS server time to Beijing time
How to install Visual Studio Code on CentOS 8
How to install and use Docker on CentOS 7
How to install RPM packages on CentOS Linux
How to set up SSH keys on CentOS 8
How to install and configure VNC on CentOS 8