Sep 13, 2018

How to Set Hostname on CentOS (RHEL)


Updated:

How to Set / Change Host Name in CentOS 7 / RHEL 7 / Oracle Linux 7


See also:

To temporarily set the host name of centos, use hostname command.
However, once the server is rebooted, the hostname will revert to it's previous setting.To permanently change the hostname, you need to edit the network file at /etc/sysconfig/network.
HOSTNAME=<value>, where <value> should be the Fully Qualified Domain Name (FQDN), such as hostname.expample.com, but can be whatever hostname is necessary.

You can also edit /etc/hosts:
127.0.0.1   myhostname localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         myhostname localhost localhost.localdomain localhost6 localhost6.localdomain6