After installing the CentOS 7 on my , I tried to change host name by modifying the /etc/sysconfig/network; it did not take an effect of the modification. Even after multiple reboots of the , the host name remains localhost.localdomain. The procedure to change the host name in 7 is now totally different from the previous version, this guide will help you to the host name on 7 / RHEL 7.

CentOS 7 supports three class of Host Names:

Static – The static host name is traditional host which can be chosen by the user and is stored in /etc/hostname file.

Transient – The transient host name is maintained by the and can be changed by DHCP and mDNS.

Pretty – It is a free form UTF -8 host name for the presentation to the user.

HostName can be,

  • 64 character in a length
  • Recommend to have FQDN
  • Consists of a-z,A-Z, 0-9, “-”, “_” and “.” only

How to Change:

Before changing the host name, let’s check the current host name.

[@localhost ~]# hostname
localhost.localdomain

1. nmtui tool:

NetworkManager tool is used to set the static host name in /etc/hostname file.

nmtui -Select Set HostName

Set the host name.

nmtui – Change HostName 2

restart the hostnamed to force the hostnamectl to notice the change of the static host name.

[[email protected] ~]# systemctl restart -hostnamed

You can verify the change in host name.

[[email protected] ~]# hostname
server.gocit.vn
[[email protected] ~]# cat /etc/hostname
server.gocit.vn
[[email protected] ~]# cat /etc/sysconfig/network
# Created by anaconda
HOSTNAME=server.gocit.vn

2. hostnamectl:

hostnamectl is used to change the host name, with this tool we can change all the three class of host name; here we look only static host name.

Check the current host name.

[[email protected] ~]# hostnamectl status
Static hostname: server.gocit.vn
Icon name: computer-vm
Chassis: vm
Machine ID: 565ea8b749544aca9d5563308f9e4bc2
Boot ID: 5c979d9b5f754df8b75a4e3aeabf2bad
: 
Operating System: CentOS  7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel:  3.10.0-123.el7.x86_64
Architecture: x86_64

Set the hostname.

[[email protected] ~]# hostnamectl set-hostname client.gocit.vn

Check the host name again (Close the session and open new session using putty or console)

[[email protected] ~]# hostnamectl status
Static hostname: client.gocit.vn
Icon name: computer-vm
Chassis: vm
Machine ID: 565ea8b749544aca9d5563308f9e4bc2
Boot ID: 5c979d9b5f754df8b75a4e3aeabf2bad
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.el7.x86_64
Architecture: x86_64

If you use this , you do not require to notify the change of the host name. Close the current session and re launch the terminal.

3. nmcli tool:

It can be used to query and setup the static host name in /etc/hostname file.

Check the hostname.

[[email protected] ~]# nmcli general hostname
client.gocit.vn

Change the host name.

[[email protected] ~]# nmcli general hostname server.gocit.vn

restart the hostnamed to force the hostnamectl to notice the change of the static host name.

[[email protected] ~]# systemctl restart systemd-hostnamed

4. Edit /etc/hostname

This is the simple but requires a reboot of the server to take an effect.

Note: Use the hostnamectl to change the host name, which is fair better than other commands and does not require to update the kernel about the change in the host name.

Print Friendly, PDF & Email

Comments

comments

Bài viết liên quan