Set Hostname on RHEL7 and CentOS 7

Change hostname on Linux

To change the hostname on you Linux server you can follow any of the below methods:

hostnamectl

hostnamectl set-hostname  <hostname>

Set hostname using hostnamectl

nmtui is a great utility which can help you not oly change the hostname but changing other network management properties like editing a connection configuration and enabling and disabling it.

Using nmtui to change the hostname

Editing /etc/hostname

Also you can edit /etc/sysconfig/network and add the following:

hostname = put_name_here

Restart the hostname daemon to confirm and check current status

systemctl restart systemd-hostnamed
hostnamectl status

Tip: changing hostname on AWS Linux instance

In aws there is an installed package called cloud-init which is responsible for the initialization of cloud instance, you need to edit that file and add the following parameter at the end of the file.

vi /etc/cloud/cloud.cfg
preserve_hostname: true

 

 


Subscribe to
for video tutorials updates