Skip to main content

CWP Installation Perquisite : Set Hostname Permanently

A computer hostname represents a unique name that gets assigned to a computer in a network in order to uniquely identify that computer in that specific network. The hostname is set at the time when the CentOS operating system is installed or if you are spinning up a virtual machine it is dynamically assigned to the instance at startup.

The hostname is used by many of the networking programs (such as sendmail, Apache servers) to identify the machine. By default, your server is started with the server’s given name as the hostname. Some software, such as cPanel, CWP requires a valid Fully Qualified Domain Name (FQDN) for the hostname.

Types of hostnames (The hostname can be configured as follows):
Static host name assigned by sysadmin. For example, “server1”, “wwwBot2”, or “”.
Transient/dynamic host name assigned by DHCP or mDNS server at run time.
Pretty host name assigned by sysadmin/end-users and it is a free-form UTF8 host name for presentation to the user. For example, “Rubel’s netbook”.

On a CentOS Linux 7 server you can use any one of the following tool to manage hostnames:
hostnamectl command : Control the system hostname. This is a recommended method.
nmtui command : Control the system hostname using text user interface (TUI).
nmcli command : Control the system hostname using CLI part of NetworkManager.

1.Show Present Hostname :
# hostnamectl 
# hostnamectl status

# hostname 
# cat   /etc/hostname
2.Change Hostname Temporary :
# hostname 
3.Change Hostname Permanently:
# hostnamectl set-hostname
# hostnamectl
   Static hostname:
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 7400071490ea4f7d931374824ad4b52c
           Boot ID: 6e1f2d76495d4b318c25c4a1195aa130
    Virtualization: vmware
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-862.14.4.el7.x86_64
      Architecture: x86-64 
It also writes this information to the /etc/hostname file as well.
# cat /etc/hostname

# vi   /etc/hostname      (To Edit)
:x  (save & quit) 
4.One thing the hostnamectl command doesn’t do is modify the /etc/hosts file, so we’ll still need to do that
# vi /etc/hosts   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
SERVER_IP     host
:x  (save & quit)

# vi   /etc/sysconfig/network
# Created by anaconda
:x  (save & quit) 
# vi  /etc/resolve.conf
# Generated by NetworkManager
:x  (save & quit)
5.Restart The services
# systemctl status  systemd-hostnamed

# systemctl enable  network.service
# systemctl restart network.service
hostnamectl status