1

hostname -i command on a Debian 9 box gives 2 different IPs. hostname -I command gives the correct IP.

As per the manual page, -i parameter shouldn't be used. It works only if the hostname can be resolved, does that mean the issue is with the DNS server?

On the local machine I cannot find the other IP anywhere.

scetoaux
  • 1,289
  • 2
  • 12
  • 26
foobar666
  • 11
  • 1
  • 3

2 Answers2

1

I think the confusion here is in the interpretation of the switches. Note:

-i, --ip-address       addresses for the host name
-I, --all-ip-addresses all addresses for the host

The lowercase i (-i) will list all addresses that can be resolved with the hostname, so, for example, your hosts file will contribute, in addition to whatever DNS resolves. In some (corporate) networks it is common to run an internal name server for hostnames on the local LAN. These addresses do not need to be "real" or in use, they are just records against that hostname.

The capital i switch (-I) will return current interface addresses associated with the host, which should match up with an "ip address" command.

sarlacii
  • 199
  • 7
0

Maybe you have those two different IP's in your /etc/hosts file for the same name of your host.

Something like this:

/etc/hostname:

myhostname

/etc/hosts:

172.16.0.1    myhostname
192.168.1.1   myhostname

At least, this can produce the effect you are seeing.

UaT
  • 41
  • 3