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,
How to Change: Before changing the host name, lets check the current host name.
1. nmtui tool: NetworkManaget tool is used to set the static host name in /etc/hostname file. Set the host name. restart the hostnamed to force the hostnamectl to notice the change in static host name.
You can verify the change in host name.
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.
Set the hostname.
Check the host name again (Close the session and open new session using putty or console)
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.
Change the host name.
restart the hostnamed to force the hostnamectl to notice the change in static host name.
4. Edit /etc/hostname This is the simple, but requires a reboot of server to take an effect.
Note: Use the hostnamectl to change the host name, which fair better than other commands and does not require to update the kernel about the change in host name. |