How to change a static hostname on RHEL7 linux with hostnamectl

Instead of changing a hostname on your Redhat 7 server manually by editing /etc/hostname you may preferably use a dedicated command hostnamectl to do this job. By default when no other options are supplied the hostnamectl command will display basic information including static hostname:

[root@rhel7 ~]# hostnamectl 
   Static hostname: rhel7
         Icon name: computer
           Chassis: n/a
        Machine ID: 75387b56d72b44b380810499805ec28a
           Boot ID: 6ad251d0e12a10e3af1894eae5fe5cb6
    Virtualization: oracle
  Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server
            Kernel: Linux 3.10.0-123.el7.x86_64
      Architecture: x86_64

Use set-hostname option change system’s hostname. Below we will supply rhel7-web argument to change the hostname to rhel7-web.

[root@rhel7 ~]# hostname
[root@rhel7 ~]# hostnamectl set-hostname rhel-web
[root@rhel7 ~]# hostname

The hostnamectl command had automatically changed a content of /etc/hostname:

[root@rhel7 ~]# cat /etc/hostname