網頁

2015年3月26日 星期四

CentOS 7.x --- How to change hostname on CentOS 7 x64

In the CentOS 7 system(minimal installation), there are three types of hostname as static, transient and pretty.
What is the different type?
The “static” hostname is stored in “/etc/hostname” file and is used to initialize the kernel hostname at boot.
The “transient” hostname is a temporary hostname which specified by DHCP or DNS server.
Both static and transient hostnames follow the same character restriction rules as Internet domain names.
As to the “pretty” hostname, it is stored in “/etc/machine-info” file and allow user to set all kinds of special characters(ex: “DAVIDWA DESKTOP”).
How to change it?
Change all types hostname
If we want to change the three types of hostname at the same time, we can do it by using the sudo hostnamectl set-hostname <new hostname> command.
Change the special type hostname
If we want to use the NetworkManage Text tool by using the sudo nmtui command, it just is used to set the static hostname in /etc/hostname file.
擷取選取區域_004.jpg


If you want to change a particular hostname only (static, transient or pretty), you can use "--static", "--transient" or "--pretty" option. For example, to change hostname permanently, you can change the static hostname by using the sudo hostnamectl --static set-hostname  <new hostname> command
After change the hostname, It may be necessary to restart the systemd-hostnamed daemon so that as to reflect the change in Static hostname by using the sudo systemctl restart systemd-hostnamed command
擷取選取區域_006.jpg
Check the current hostname
If we want to view the hostname of the CentOS 7 system, you can use “hostnamectl” or “hostnamectl status” command directly.擷取選取區域_008.jpg
or use hostnamectl status [--static|--transient|--pretty] to view static, transient or pretty hostname, respectively.

After reboot it and log in again, the system will display the new hostname now.
擷取選取區域_010.jpg
Since 2010 Design by Davidwa
©Copyright Davidwa Inc. All rights reserved.