Header Ads

How to Change HostName in CentOS 7 / RHEL 7

Change HostName in CentOS 7 / RHEL 7


After installing RHEL 7.3 in my pc,i tried to change or modify hostname of that pc but i didn't find any effect ,even after multiple restarts.

After an hour of web surfing I found that the procedure is totally different than previous version of CentOS/RHEL version.


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 kernel 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, lets check the current host name.










[root@ashokkuikel ~]# hostname
station.ashokkuikel.com.np




  1. nmtui tool


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



fig : nmtui -Select Set HostName

Set the host name.




                                                                        nmtui – Change HostName 2

 

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











[root@localhost ~]# systemctl restart systemd-hostnamed



You can verify the change in host name.











[root@ashokkuikel ~]# hostname
server.ashokkuikel.com.np
[root@ashokkuikel ~]# cat /etc/hostname
server.ashokkuikel.com.np
[root@ashokkuikel ~]# cat /etc/sysconfig/network
# Created by anaconda
HOSTNAME=server.ashokkuikel.com.np


 


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.











[root@ashokkuikel ~]# hostnamectl status











Static hostname: station.ashokkuikel.com.np
Icon name: computer-vm
Chassis: vm
Machine ID: dbb0c4ed3cdb4441bc7640855160a5d0
Boot ID: 31dedcbda16b451f98f4646389b1eb0e
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-514.el7.x86_64
Architecture: x86-64



Set the hostname.










[root@ashokkuikel ~]# hostnamectl set-hostname server.ashokkuikel.com.np


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











[root@ashokkuikel ~]# hostnamectl status











Static hostname: server.ashokkuikel.com.np
Icon name: computer-vm
Chassis: vm
Machine ID: dbb0c4ed3cdb4441bc7640855160a5d0
Boot ID: 31dedcbda16b451f98f4646389b1eb0e
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-514.el7.x86_64
Architecture: x86-64



If you use this command, you do not require to notify the change in 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.











[root@ashokkuikel ~]# nmcli general hostname server.ashokkuikel.com.np



Change the host name.











[root@ashokkuikel ~]# nmcli general hostname server.ashokkuikel.com.np



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











[root@ashokkuikel ~]# systemctl restart systemd-hostnamed



4. Edit /etc/hostname


it's simple, but requires a reboot of server to take an effect.

How to Change HostName in CentOS 7 / RHEL 7 How to Change HostName in CentOS 7 / RHEL 7 Reviewed by Ashok on Monday, July 03, 2017 Rating: 5

No comments

Recent Posts