Change hostname permanently in CentOS 7

In this simple tutorial, I ‘ll show you how to change permanently the hostname of a CentOS.  With new version of CentOS many things have changed a lot form the previous version of the Operating System.

In CentOS 7 there is a tool named hostnamectl with which you can see information of your system and set permanently the hostname of your machine.

I will give you a simple example. After a simple installation in which I didn’t set any hostname, I run the following command:

# hostnamectl

and I get the following output:

 Static hostname: localhost.localdomain
 Icon name: computer
 Chassis: n/a
 Machine ID: df183fd68ee94f7c818fb5a1c5263481
 Boot ID: 12861ba509af4e6ab16142863b141343
 Virtualization: vmware
 Operating System: CentOS Linux 7 (Core)
 CPE OS Name: cpe:/o:centos:centos:7
 Kernel: Linux 3.10.0-123.el7.x86_64
 Architecture: x86_64

To change hostname permanently, I run:

#  hostnamectl set-hostname myserver.webplay.pro

and then I run hostnamectl again to see the changes:

 Static hostname: myserver.webplay.pro
 Icon name: computer
 Chassis: n/a
 Machine ID: df183fd68ee94f7c818fb5a1c5263481
 Boot ID: 12861ba509af4e6ab16142863b141343
 Virtualization: vmware
 Operating System: CentOS Linux 7 (Core)
 CPE OS Name: cpe:/o:centos:centos:7
 Kernel: Linux 3.10.0-123.el7.x86_64
 Architecture: x86_64

This change persists on reboots

Leave a Reply

Your email address will not be published. Required fields are marked *

Prove me that you are not a robot :) * Time limit is exhausted. Please reload the CAPTCHA.