How to Change Hostname in RHEL / CentOS 7.0

Posted at November 11, 2016 at 12:58 pm by Jithin

Watch the following video if you want to know how to change VPS hostname via my.interserver.net

 

In this tutorial, we will be discussing on how to change the hostname in RHEL / CentOS 7.0. This is possible way much easier through command line.

 

Check Hostname

To check the hostname, type the following command:

$ hostname

The default hostname of the system is localhost.localdomain. We can change it by editing the file, /etc/hostname.  This can be done by opening the file with a text editor and entering in  the desired hostname.

$ vi /etc/hostname

Please note that after the modification the file must be saved. If it has not changed, then try restarting the server. Then confirm your new hostname in the hostname file.

 

Using Hostnamectl

With the help of hostnamectl we can easily control the Linux system hostname. You can also use this tool to change the hostname in a few easy steps. The present hostname can be checked by:

$ hostnamectl status

The sample output will be the following:

 Static hostname         : centos7.is.cc

Icon name           : computer-vm

Chassis              : vm

Machine ID          : fae4b37f37c05cdec9c7739d27983bbe

Boot ID              : 8e5190a4f1c645ce9a7c6ed1f7c94cb3

Virtualization           : kvm

Operating System      : CentOS Linux 7 (Core)

CPE OS Name        : cpe:/o:centos:centos:7

Kernel               : Linux 3.10.0-327.22.2.el7.x86_64

Architecture          : x86-64

To change the hostname try following command:

$ hostnamectl set-hostname TEST

You can rechek the hostname by using the command:

$ hostname

TEST

It is recommended to restart systemd-hostnamed daemon in order to update the changes.

$ sudo systemctl restart systemd-hostnamed

 

Using Nmtui

Network Manager text interface tool (NMTUI) is a graphical interface tool which allows to change the hostname easily. Type the following command in terminal:

$ nmtui

A list of available options will be shown and you can select the required option from there. Change the hostname from localhost.localdomain to the desired name. Press OK to apply the modification done. For further verification type hostname in the command line.

 

Using Nmcli

This command line tool is used to manage the Network Manager and  change the hostname.  The following command can be used to check the hostname:

$ nmcli general hostname

The below given command can be used to change the hostname

$ nmcli general hostname TEST

You can recheck it by using the command:

$ nmcli general hostname

TEST

This will request for your password via a GUI interface. If you are running this command remotely remember to use root or sudo:

$ sudo nmcli general hostname grace

You can then check the hostname with the command hostname or nmcli general hostname.

 

If you need any further assistance please contact our support department.

 

 

5.00 avg. rating (89% score) - 1 vote

You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Reply