说明和使用
hostnamectl 是一个用于管理系统主机名的命令行工具,可以用来查看和设置系统的主机名。以下是 hostnamectl 命令的说明和使用方法:
查看当前主机名:
$ hostnamectl
查看主机名详细信息,包括静态和动态的主机名:
$ hostnamectl status
查看主机名的静态信息:
$ hostnamectl --static
查看主机名的动态信息:
$ hostnamectl --transient
查看主机名的 Pretty 格式(用户友好的名称):
$ hostnamectl --pretty
设置新的静态主机名:
$ sudo hostnamectl set-hostname new-hostname
设置新的动态主机名:
$ sudo hostnamectl set-hostname new-hostname --transient
设置新的 Pretty 主机名:
$ sudo hostnamectl set-hostname new-hostname --pretty
设置时区:
$ sudo timedatectl set-timezone Asia/Shanghai
重启主机:
$ sudo systemctl reboot
请注意,在设置主机名时需要使用管理员权限,使用 sudo 命令。另外,设置主机名后可能需要重启系统才能使改动生效。
Simply put
hostnamectl is a command-line tool used to query and control the system hostname and related settings in Linux distributions that use systemd. Here is an explanation of the command and its usage:
- hostnamectl is used to interact with the system’s hostname settings.
- By running hostnamectl without any options, it displays the current hostname and related information.
- To set a new hostname, you can use the set-hostname option followed by the desired hostname. For example: sudo hostnamectl set-hostname newhostname .
- To check the status and details of the system’s hostname configuration, you can use the status option. For example: hostnamectl status .
- hostnamectl also provides options to control the static hostname, transient hostname, and chassis type.