Linux command
hostnamectl 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Example
hostnamectl
Example
sudo hostnamectl set-hostname "hostname"
Example
sudo hostnamectl set-hostname --static "hostname.example.com" && sudo hostnamectl set-hostname --pretty "My Computer"
Example
sudo hostnamectl set-hostname --pretty ""
Example
sudo hostnamectl set-chassis desktop
Example
sudo hostnamectl set-deployment production
说明
hostnamectl queries and changes the system hostname and related machine metadata. It manages three hostname types: static (persistent), pretty (human-readable), and transient (temporary).
参数
- --static
- Operate on static hostname only
- --transient
- Operate on transient hostname only
- --pretty
- Operate on pretty hostname only
- --no-ask-password
- Do not prompt for password
- -H, --host
- Execute operation on remote host
- -M, --machine
- Execute operation on container
- -j, --json
- Output in JSON format
FAQ
What is the hostnamectl command used for?
hostnamectl queries and changes the system hostname and related machine metadata. It manages three hostname types: static (persistent), pretty (human-readable), and transient (temporary).
How do I run a basic hostnamectl example?
Run `hostnamectl` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does --static do in hostnamectl?
Operate on static hostname only