In Linux, a hostname is a unique name that identifies a device on a network, and is used to identify the device in various network protocols and systems. A hostname can be set during the installation of the operating system or later using various commands.
There are several reasons why you might need to change the hostname in Linux. One common reason is to avoid duplicate names on the same network. If you have more than one computer on your home network and want them all running Linux, you’re going to want to change the default hostnames to avoid problems.
Changing a Server’s Hostname
To change the hostname of your system, follow the steps below. In this example, we are changing the hostname of our server to “NewHostname”.
sudo hostnamectl set-hostname NewHostname
Now, you can confirm that the change has occurred by checking the new hostname using either of the following commands:
hostname OR hostnamectl
An Important Note for cPanel Users
If you’ve changed your hostname in a cPanel environment, it is recommended that you run the following command to update your cPanel license information on the new hostname. This will allow you to avoid a potential invalid cPanel license error.
/usr/local/cpanel/cpkeyclt