To modify the hostname on CentOS

Method One:

 

1.Open a terminal or SSH into the Linux system.
2.Log in to the system with root privileges.
3.Use the following command to check the current hostname:
  • hostname 

 

 

4.Use the following command to change the hostname:

  • hostnamectl set-hostname <new_hostname> 

Replace new-hostname with the desired hostname you want to set.

 

 

5.Reboot the system for the changes to take effect, or you can run the following command to apply the new hostname without rebooting:

  • systemctl restart systemd-hostnamed

 

 

6.To verify if the hostname has been successfully changed, use the following command:

  • hostname 

 

 

If the output matches the new hostname you set, it indicates that the hostname has been successfully changed. After rebooting the system, verify that the modification has taken effect.

 

 

 

Method 2:

 

1.Open the "/etc/hostname" file using the following command:

  • vi /etc/hostname 

 

 

 

2.To change the hostname to your desired name in the opened file

To start editing, press "a" and delete the previous hostname. Set your new hostname. After making the changes, press "Esc" to exit edit mode. Then, press Shift+":" and type "wq" to save and exit.

 

 

3.After restarting the Linux system, check whether the hostname has taken effect.

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

CentOS 7.x Firewall: Enable/Disable and Add Ports

  In CentOS 7.x, the default firewall is firewalld. Here is an example using CentOS 7.6...

How to enable/disable ping on Linux system

To prevent others from discovering and potentially attacking your machine through network ping...

How to View Memory Usage and Clear Cache in Linux System

Sometimes, when a server becomes unresponsive, it may not necessarily be due to high CPU usage....

How to remotely access a Linux system using Putty tool

Introduction to Putty software PuTTY is a Telnet, SSH, rlogin, raw TCP, and serial interface...

Linux System RuiSu Installation Tutorial

Note: The prerequisite for installing RuiSu is to ensure that the network card is in the "eth"...