How to Change Hostname in CentOS

  • Last updated: Oct 12, 2024
  • Views: 11
  • Author: Admin
How to Change Hostname in CentOS

Hello colleagues.

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.

 

Hostname types.

  1. Static hostname.
  2. Nice hostname.
  3. Temporary hostname.

 

Static 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.

Nice hostname.

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.

Temporary hostname.

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:

$. hostname

change hostname linux

 

$. hostnamectl

change hostname linux

 

$. cat /etc/hostname

change hostname linux


 

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


 

Result.

change hostname linux


 

Thank you all, I hope my article was of some help to you.

 

SIMILAR ARTICLES