Casbay Knowledge Base

Search our articles or browse by category below

Linux VPS Server Guide on Changing Hostname Using Commands in 4 Simple Steps

Last modified: October 1, 2022
Estimated reading time: 1 min

A hostname is a name of a device within a network and is used by multiple network services as an identifier. There are no restrictions in naming hostname within a private network, however, the hostname will need to be combined together with the hostname when it has access to the Internet. In this article, we will be guiding you on how to change your hostname within a Linux VPS server using the hostname and hostnamectl commands. The Linux distribution used in this guide is CentOS 7.

Step 1: Gaining Privilege

First, you will need to connect to the server using SSH. To change a hostname, you need to be a root user. You can gain the privilege of a root user using the following command.

su

Enter the root password in order to proceed.

Step 2: Preview Hostname

To view the current hostname, run the following command.

hostname

You may also perform the same action with the following command.

hostnamectl

However, this command will provide more information regarding the hostname.

Step 3: Changing Hostname

To change the hostname, run the following command.

hostnamectl set-hostname <new_hostname>

Replace the <new_hostname> with a hostname that you planned on changing it into.

Step 4: Verify Hostname

To verify if the changes were made to the hostname, run the following command.

hostnamectl

You will be able to see the new hostname that you have just changed.

Alternate Method

Another method of changing your hostname is by opening the directory “/etc/hostname” with any text editor of your preference.

nano /etc/hostname

Then, look for a single line where your hostname is located, then replace it with a hostname of your preference. Make save changes and exit the file. To verify if your hostname is changed, run the following command.

hostnamectl

Hopefully, this article is able to help you change to a hostname of your own.

Was this article helpful?
Dislike 0
Previous: FFmpeg Installation Guide For Linux Based VPS in 4 Simple Steps (Debian)
Next: Quick phpMyAdmin Installation On Linux VPS Server For Ubuntu 18.04