CentOS 7 hostname management¶
In CentOS 7, system hostnames are managed primarily through the hostnamectl utility, which is part of the systemd system and service manager.^[600-developer__linux__centos7-command.md]
Viewing the current hostname¶
To display the current hostname of the system, use the following command without any arguments:^[600-developer__linux__centos7-command.md]
hostnamectl
Setting a new hostname¶
The static hostname can be set dynamically using the set-hostname subcommand.^[600-developer__linux__centos7-command.md]
Command syntax¶
hostnamectl set-hostname <new_hostname>
For example, to set the hostname to tk.yudady.com:^[600-developer__linux__centos7-command.md]
hostnamectl set-hostname tk.yudady.com
Persistent configuration (hosts file)¶
While hostnamectl configures the kernel hostname, it is standard practice to ensure the new hostname is also mapped within the local system's host file for proper network resolution.^[600-developer__linux__centos7-command.md]
To edit this file, use a text editor such as vim:^[600-developer__linux__centos7-command.md]
vim /etc/hosts
Sources¶
^[600-developer__linux__centos7-command.md]
Related¶
- [[Systemd]]