hostname [-v] [-a|--alias] [-d|--domain] [-f|--fqdn|--long] [-A|--all-fqdns]
[-i|--ip-address] [-I|--all-ip-addresses] [-s|--short] [-y|--yp|--nis]
hostname [-v] [-b|--boot] [-F|--file file name] [hostname]
hostname [-v] [-h|--help] [-V|--version]
选件
-a,-- alias
|
显示主机的别名(如果使用)。此选项已弃用,不应再使用。
|
-A,--all-fqdns
|
显示机器的每个FQDN。此选项在所有已配置的网络接口上枚举所有已配置的网络地址,并将其转换为DNS域名。跳过无法翻译的地址(即因为它们没有适当的反向DNS条目)。请注意,不同的地址可能解析为相同的名称,因此输出可能包含重复的条目。不要对输出的顺序做任何假设。
|
-b,--boot
|
始终设置hostname;这允许-F指定的文件不存在或为空,在这种情况下,如果尚未设置默认hostnamelocalhost,则将使用它。
|
-d,-- domain
|
显示DNS域的名称。不要使用命令域名来获取DNS域名,因为它显示的是NIS域名而不是DNS域名。请改用dnsdomainname。请参阅FQDN部分中的警告,并尽可能避免使用此选项。
|
-f,-- fqdn,-- long
|
显示FQDN(完全合格的域名)。FQDN由短hostname和DNS域名组成。除非您使用BIND(伯克利Internet名称域)或NIS进行主机查找,否则您可以在/ etc / hosts文件中更改FQDN和DNS域名(属于FQDN)。请参阅FQDN部分中的警告,并尽可能避免使用此选项。使用hostname--all-fqdns。
|
-F,--file filename
|
从指定文件中读取hostname。注释(以' # '开头的行)将被忽略。
|
-i,--ip-address
|
显示hostname的网络地址。请注意,这仅在hostname可以解析的情况下有效。尽可能避免使用此选项;请改用hostname--all-ip-addresses。
|
-I,-- all-ip-addresss
|
显示主机的所有网络地址。此选项枚举所有网络接口上的所有已配置地址。省略了环回接口和IPv6链接本地地址。与选项-i相反,此选项不依赖于名称解析。不要对输出的顺序做任何假设。
|
-s,-- short
|
显示简短的hostname。这是在第一个点处剪切的hostname。
|
-v,-- verbose
|
要详细所有输出。
|
-V,-- version
|
在标准输出上打印版本信息,并成功退出。
|
-y,-- yp,-- nis
|
显示NIS域名。如果给定了一个参数(或--file name),那么root(超级用户)也可以设置一个新的NIS域。
|
-h,--help
|
打印帮助消息并退出。
|
FQDN
系统的FQDN(标准域名)是解析程序为hostname返回的名称,例如mysubdomain.example.com。通常是hostname,后跟DNS域名(第一个点之后的部分)。您可以使用hostname--fqdn检查FQDN或使用dnsdomainname检查域名。
您不能使用hostname或dnsdomainname更改FQDN 。
推荐的设置FQDN的方法是使用/ etc / hosts,DNS或NIS使hostname成为标准名称的别名。例如,如果hostname是“ mysubdomain ”,则/ etc / hosts中可能有一行,内容为:
127.0.1.1 ursula.example.com ursula
从技术上讲:FQDN是gethostr返回的hostname的getaddrinfo返回名称。DNS域名是第一个点之后的部分。
因此,如何更改它取决于解析器的配置(通常在/etc/host.conf中)。通常,hosts文件是在DNS或NIS之前解析的,因此最常见的是在/ etc / hosts中更改FQDN 。
如果机器具有多个网络接口/地址或在移动环境中使用,则它可能具有多个FQDN /域名,或者根本没有。因此,请避免使用hostname--fqdn,hostname--domain和dnsdomainname。
hostname--ip-address受相同的限制,因此也应避免使用。
档案
/ etc /hostname
|
从历史上看,该文件仅包含hostname,而不包含完整的规范FQDN。如今,大多数软件都可以在此处处理完整的FQDN。引导时,系统初始化脚本会读取此文件以设置hostname。
|
/ etc / hosts
|
通常,这里是通过将hostname别名为FQDN来设置域名的地方。
|
hostname [-v] [-a|--alias] [-d|--domain] [-f|--fqdn|--long] [-A|--all-fqdns]
[-i|--ip-address] [-I|--all-ip-addresses] [-s|--short] [-y|--yp|--nis]
hostname [-v] [-b|--boot] [-F|--file file name] [hostname]
hostname [-v] [-h|--help] [-V|--version]
Options
-a, --alias
|
Display the alias name of the host (if used). This option is deprecated and should not be used anymore.
|
-A, --all-fqdns
|
Displays every FQDN of the machine. This option enumerates all configured network addresses on all configured network interfaces, and translates them to DNS domain names. Addresses that cannot be translated (i.e. because they do not have an appropriate reverse DNS entry) are skipped. Note that different addresses may resolve to the same name, therefore the output may contain duplicate entries. Do not make any assumptions about the order of the output.
|
-b, --boot
|
Always set a hostname; this allows the file specified by -F to be non-existant or empty, in which case the default hostname localhost will be used if none is yet set.
|
-d, --domain
|
Display the name of the DNS domain. Don't use the command domainname to get the DNS domain name because it shows the NIS domain name and not the DNS domain name. Use dnsdomainname instead. See the warnings in the FQDN section, and avoid using this option if at all possible.
|
-f, --fqdn, --long
|
Display the FQDN (fully qualified domain name). A FQDN consists of a short hostname and the DNS domain name. Unless you are using BIND (Berkeley Internet Name Domain) or NIS for host lookups, you can change the FQDN and the DNS domain name (which is part of the FQDN) in the /etc/hosts file. See the warnings in the FQDN section, and avoid using this option if at all possible; use hostname --all-fqdns instead.
|
-F, --file file name
|
Read the hostname from the specified file. Comments (lines starting with a `#') are ignored.
|
-i, --ip-address
|
Display the network address(es) of the hostname. Note that this works only if the hostname can be resolved. Avoid using this option if at all possible; use hostname --all-ip-addresses instead.
|
-I, --all-ip-addresses
|
Display all network addresses of the host. This option enumerates all configured addresses on all network interfaces. The loopback interface and IPv6 link-local addresses are omitted. Contrary to option -i, this option does not depend on name resolution. Do not make any assumptions about the order of the output.
|
-s, --short
|
Display the short hostname. This is the hostname cut at the first dot.
|
-v, --verbose
|
Be verbose with all output.
|
-V, --version
|
Print version information on standard output and exit successfully.
|
-y, --yp, --nis
|
Display the NIS domain name. If a parameter is given (or --file name ) then root (the superuser) can also set a new NIS domain.
|
-h, --help
|
Print a help message and exit.
|
The FQDN
The FQDN (fully qualified domain name) of the system is the name that the resolver returns for the hostname, such as mysubdomain.example.com. It is usually the hostname followed by the DNS domain name (the part after the first dot). You can check the FQDN using hostname --fqdn or the domain name using dnsdomainname.
You cannot change the FQDN with hostname or dnsdomainname.
The recommended method of setting the FQDN is to make the hostname be an alias for the fully qualified name using /etc/hosts, DNS, or NIS. For example, if the hostname was "mysubdomain", one might have a line in /etc/hosts which reads:
127.0.1.1 ursula.example.com ursula
Technically: The FQDN is the name getaddrinfo returns for the hostname returned by gethostname. The DNS domain name is the part after the first dot.
Therefore it depends on the configuration of the resolver (usually in /etc/host.conf) how you can change it. Usually, the hosts file is parsed before DNS or NIS, so it is most common to change the FQDN in /etc/hosts.
If a machine has multiple network interfaces/addresses or is used in a mobile environment, then it may either have multiple FQDNs/domain names or none at all. Therefore avoid using hostname --fqdn, hostname --domain and dnsdomainname.
hostname --ip-address is subject to the same limitations so it should be avoided as well.
Files
/etc/hostname
|
Historically this file was supposed to only contain the hostname and not the full canonical FQDN. Nowadays most software can cope with a full FQDN here. This file is read at boot time by the system initialization scripts to set the hostname.
|
/etc/hosts
|
Usually, this is where one sets the domain name by aliasing the hostname to the FQDN.
|
未知的网友