Skip to main content

VestaCP Installation Perquisite : Part 3 Set Hostname Permanently

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 , VestaCP 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 “host.datahead.biz”.
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 status
# cat   /etc/hostname
2.Change Hostname Temporary :
# hostname host.datahead.biz 
3.Change Hostname Permanently:
# hostnamectl set-hostname host.datahead.biz
# hostnamectl
   Static hostname: host.datahead.biz
         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
host.datahead.biz

# vi   /etc/hostname      (To Edit)
host.datahead.biz
: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
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
SERVER_IP    host.datahead.biz     host
:x  (save & quit)

# vi   /etc/sysconfig/network
# Created by anaconda  
HOSTNAME=host.datahead.biz
:x  (save & quit) 
# vi  /etc/resolve.conf
# Generated by NetworkManager
search datahead.biz
nameserver   8.8.4.4
nameserver   8.8.8.8
:x  (save & quit)
5.Restart The services
# systemctl status  systemd-hostnamed

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

Comments