Search code examples
bashconnectionip-addressarchlinuxhostname

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


Resolving my local hostname (the one returned by hostname) does not yield the right ip address. Why could that be and how do I fix it?

$ 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

Help is very much appreciated!

Edit:

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

Solution

  • hostname -i relies on DNS resolution to return the IP address of the given hostname. Either your /etc/hosts or dns resolver return that hostname to the incorrect IP address.