`hostname -i` 地址不同于 `ifconfig` 地址

`hostname -i` address differs from `ifconfig` address

解析我的本地主机名(由 hostname 返回的主机名)没有产生正确的 IP 地址。为什么会这样,我该如何解决?

$ hostname -i
10.21.16.206

$ ping 10.21.16.206
PING 10.21.16.206 (10.21.16.206) 56(84) bytes of data.
From 10.21.16.159 icmp_seq=1 Destination Host Unreachable

$ ifconfig
(...)
inet 10.21.16.159  netmask 255.255.252.0  broadcast 10.21.19.255
(...)

10.21.16.206 != 10.21.16.159

$ host 10.21.16.159
 Host 159.16.21.10.in-addr.arpa. not found: 3(NXDOMAIN)

$ host 10.21.16.206
 206.16.21.10.in-addr.arpa domain name pointer lxka-czc1166cxw.united.domain.

$ resolveip 10.21.16.159
Host name of 10.21.16.159 is lxka-czc1166cxw

$ resolveip 10.21.16.206
Host name of 10.21.16.206 is lxka-czc1166cxw.united.domain

非常感谢您的帮助!

编辑:

$ host $(hostname)
lxka-czc1166cxw.united.domain has address 10.21.16.206

hostname -i 依赖 DNS 解析 return 给定主机名的 IP 地址。您的 /etc/hosts 或 dns 解析器 return 将主机名指向错误的 IP 地址。

来自主机名的手册页:

option -i, --ip-address

Display the network address(es) of the host name. Note that this works only if the host name can be resolved. Avoid using this option;

使用 主机名 --all-ip-addresses 或 使用 hostname -I 选项代替它。