How to change the Hostname on a CentOS 7 server via the command line (SSH)

By | October 21, 2017

By default, your server is started with the server’s given name as the hostname. Some software, requires a valid Fully Qualified Domain Name (FQDN) for the hostname to be used during their DNS resolution. This article describes how to change a server hostname in CentOS.

Step 1 – Login to your server as a user with root privilege.

[root@en-030 ~]#

Step 2 – Check current hostname:

[root@en-030 ~]# hostname -f

Step 3 – Now here’s the magic command to change default CentOS 7 hostname without having to reboot your server: by running the command line below:

[root@en-030 ~]# hostnamectl set-hostname --static

Step 4 – You may also want to find out status of your server and its hostname using hostnamectl command:

[root@en-030 ~]# hostnamectl status

Your output should look something like this:

[root@en-030 ~]# hostnamectl status
   Static hostname:
         Icon name: computer-server
           Chassis: server
        Machine ID: da8c65185c6b43ee9312d647d153b8fc
           Boot ID: c50ca6a8ecb742079a7a0ef358a2c27e
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-693.2.2.el7.x86_64
      Architecture: x86-64

It recommended that static name match the fully-qualified domain name (FQDN) used for the machine in DNS.


Congratulations! you have successfully configured hostname on CentOS 7 server via command line. You can now easily resolve fully qualified domain name (fqdn) server. Try it out today! Feel free to comment me if you have any questions.