Sunday, March 22, 2015

How to change Hostname in Linux (CentOS / RHEL 7)



There are three classes for hostname in Linux


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.

How to check current hostname

 

Type in terminal like below
[akila@localhost ~]# hostname
localhost.localdomain


Below is show how to set hostname using networkManagement Tool(nmtui)


Type nmtui in command prompt,

[akila@localhost ~]# nmtui

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

[akila@localhost ~]# nmtui –select set hostname
You can change hostname using tool. After changing the hostname restart hostnamed service as below,
[akila@localhost ~]# systemctl restart system-hostnamed
Now check the hostname again. You can see changed hostname,
[akila@localhost ~]# hostname


Using hostnamectl command,


To check the status of hostname, type below command,
[akila@localhost ~]# hostnamectl status


Set the hostname using below command,
[akila@localhost ~]# hostnamectl set-hostname newHostName

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.

No comments:

Post a Comment