You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.5 KiB

5 years ago
# **hostname**
7 years ago
6 years ago
## 说明
7 years ago
5 years ago
**hostname命令** 用于显示和设置系统的主机名称。环境变量HOSTNAME也保存了当前的主机名。在使用hostname命令设置主机名后
统并不会永久保存新的主机名,重新启动机器之后还是原来的主机名。如果需要永久修改主机名,需要同时修改`/etc/hosts`和
`/etc/sysconfig/network`的相关内容
7 years ago
5 years ago
## 选项
7 years ago
5 years ago
```markdown
Usage: hostname [-b] {hostname|-F file} set host name (from file)
hostname [-a|-A|-d|-f|-i|-I|-s|-y] display formatted name
hostname display host name
7 years ago
5 years ago
{yp,nis,}domainname {nisdomain|-F file} set NIS domain name (from file)
{yp,nis,}domainname display NIS domain name
7 years ago
5 years ago
dnsdomainname display dns domain name
7 years ago
5 years ago
Program name:
{yp,nis,}domainname=hostname -y
dnsdomainname=hostname -d
7 years ago
5 years ago
-a, --alias 显示主机别名
-A, --all-fqdns all long host names (FQDNs)
-b, --boot set default hostname if none available
-d, --domain 显示DNS域名
-f, --fqdn, --long 显示FQDN名称
-F, --file read host name or NIS domain name from given file
-i, --ip-address 显示主机的ip地址
-I, --all-ip-addresses all addresses for the host
-s, --short 显示短主机名称,在第一个点处截断
-y, --yp, --nis 显示NIS/YP域名
7 years ago
```
5 years ago
## 实例
```bash
hostname -i # 查寻本地主机的IP地址同等于host `hostname`
7 years ago
```