如何从
/etc/hosts
中获取主机名?通过编写hostname
吗?
那DNS域名呢,我该怎么办?我如何通过命令行获取这些名称?/etc/hosts
中获取主机名?通过编写hostname
吗?
那DNS域名呢,我该怎么办?我如何通过命令行获取这些名称?hostname
/etc/hostname
hostname --help
以获取许多选项。从帮助中...-s, --short short host name
-a, --alias alias names
-i, --ip-address addresses for the host name
-I, --all-ip-addresses all addresses for the host
-f, --fqdn, --long long host name (FQDN)
-A, --all-fqdns all long host names (FQDNs)
-d, --domain DNS domain name
-y, --yp, --nis NIS/YP domain name
-b, --boot set default hostname if none available
-F, --file read host name or NIS domain name from given file
hostname -f
/etc/hostname
里有什么东西吗?这是我们这里通常为apache编辑的一个文件。示例主题:http://askubuntu.com/a/218499/15811 - Rinzwindlocalhost
只是网络上“自己”的昵称。所有计算机(包括虚拟机)都可以使用localhost
地址连接到自己。 - Melebius假设你想要获取本地(局域网)的IPv4地址....
为了避免服务器返回一个将你的IPv4和IPv6地址组合在一起的长字符串,在bash脚本中使用以下代码:
LOCALIP=$(hostname -I | awk '{print $1}')
hostname -I | awk '{print $1}'