hostname
行程與系統
用法
hostname [-f]印出或設定本機名稱;`hostname web01` 只保留到下次重開機,要永久生效得用 Linux 的 `hostnamectl` 或 macOS 的 `scutil --set HostName`,而列出全部 IP 的 `-I` 只有 Linux 有。
常用選項
| 選項 | 含義 |
|---|---|
| -s | Short name only, up to the first dot. |
| -f | Fully qualified domain name (Linux). |
| -I | All IP addresses of this host, space separated. Linux only, capital i. |
| -i | Resolve the host name; depends on /etc/hosts, so it often prints 127.0.1.1 (Linux). |
| hostname <newname> | Change it until the next reboot only. |
範例
hostname -fThe full name other machines see.
hostname -IEvery local IP without parsing ip or ifconfig output (Linux).
sudo hostnamectl set-hostname web01The permanent change on systemd; macOS uses scutil --set HostName.
看什麼在跑、什麼在吃機器。先弄清是什麼,再決定殺不殺。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. hostname 是做什麼的?
印出或設定本機名稱;`hostname web01` 只保留到下次重開機,要永久生效得用 Linux 的 `hostnamectl` 或 macOS 的 `scutil --set HostName`,而列出全部 IP 的 `-I` 只有 Linux 有。
Q. 怎麼寫?
hostname [-f] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 5 個,完整列表在 man hostname。這條命令屬於行程與系統。
相關命令
man 手冊: man hostname