Skip to main content

Set RHEL7 Hostname

·257 words·2 mins

Overview #

This HowTo will provide some information about the different types of hostnames and how to set them in RHEL7 (Redhat 7 or CentOS 7) based machine. If you have built your new RHEL7 based machine and have now got a bit stuck over how to change the hostname from localhost.localdomain to what ever you want this is the how to for you.

Types Of Hostnames #

There are three types of hostnames: Static, Pretty and Transient.

Static Hostname #

The Static hostname is essentially the traditional hostname which is stored in the “/etc/hostname” file.

[user@server ~]$ cat /etc/hostname

Transient Hostname #

The Transient hostname is a dynamic hostname which is maintained at a kernel level. It is initialized by the static hostname, but can be changed by DHCP and other network services.

Pretty Hostname #

The Pretty hostname is a free form hostname for presentation to the user.

Set The Hostname #

The hostname can be changed by editing the “/etc/hostname” file or with the hostnamectl command.

[root@server ~]# hostnamectl set-hostname

This command will set all three hostnames at the same time, but all three can be set individually using the “-static”, “-transient” or “-pretty” flags.

Validate “/etc/hostname” has been updated

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

Hostname Information #

You can see a bit of information with the hostnamectl command which is very useful. man hostnamectl

[root@server ~]# hostnamectl
   Static hostname: server.domain.tld
         Icon name: computer-vm
           Chassis: vm
        Machine ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
           Boot ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-123.4.4.el7.x86_64
      Architecture: x86_64