How to Change Hostname in CentOS/RHEL 8
- Last updated: Nov 3, 2023
- Views: 216
- Author: Admin
In today's article, we will talk about several ways to change the hostname in Linux. We will show all examples on the Centos 8 Stream operating system.
When system administrators manage a large network of systems and monitor a large stream of packets, it becomes very difficult to understand which packet goes where. To identify the system, ip addresses or hostname are usually used. The hostname is considered the most convenient and easy to remember way to identify the system.
The hostname is simply the name of your machine or server on your network. The hostname is set during Centos 8 installation automatically or the system administrator specifies the name explicitly. The assigned server name is not always easy to remember when you have a large network, and during the operation of the network you will want to change the host name of this server.
- Static hostname.
- Nice hostname.
- Temporary hostname.
The simplest and most traditional hostname is set by the system administrator and is used to identify the server from other servers on the network. This hostname is stored in the /etc/hostname file.
A pretty hostname is used to present a more user-friendly hostname because it does not contain a UTF-8 hostname and allows non-standard characters.
The Linux kernel maintains a temporary hostname, it can be changed after a reboot by a DNS or DHCP server.
1. Show current server name.
In order to display the current server name, we use simple commands in the console:
$. cat /etc/hostname
2. Change the hostname followed by a server restart.
In order to change the hostname, we need to open the /etc/hostname file for writing.
$. sudo vi /etc/hostname
In this file, we change the hostname to the one we need and save the file. The new name you have assigned will not take effect immediately and you will need to restart your server.
$. sudo reboot
After a reboot, you will have the new hostname of your server.
3. Changes the hostname without restarting the server.
In order for us to change the hostname, we will use a tool called hostnamectl. This command works not only on Centos 8 or RHEL distributions, but on others too.
Command to set static hostname:
$. sudo hostnamectl set-hostname inzhener.loc
The command to set a pretty hostname is:
$. sudo hostnamectl set-hostname "My blog IT-INZHENER" --pretty
Command to set temporary hostname:
$. sudo hostnamectl set-hostname temp.it-inzhener.com --transient
Thank you all, I hope my article was of some help to you.