Unix ping and host commands result in different IP addresses for the same domain name

1

My understanding is that the unix ping and host commands should generate the same IP address given the same domain. If you look at these two commands:

$ ping api.dev.myserver.com
PING api.dev.myserver.com (10.11.12.15): 56 data bytes
64 bytes from 10.11.12.15: icmp_seq=0 ttl=64 time=0.303 ms
(...)

$ host api.dev.myserver.com
api.dev.myserver.com has address 69.68.153.135

The first is my local development VM, and shows the desirable IP as I've specified in my /etc/hosts file. The second shows the live box, circumventing my /etc/hosts file. I have flushed my DNS cache to verify that's not causing the difference.

kelorek

Posted 2013-11-11T18:27:22.950

Reputation: 210

Answers

2

the host command (and nslookup command) ignore /etc/hosts, as you've found. They work against nameservers (DNS), not local files.

pretty sure getent ahosts (host) will also use /etc/hosts, like ping does.

Sirex

Posted 2013-11-11T18:27:22.950

Reputation: 10 321

2

Host is a dns query application and does not look in the hosts file. See http://linux.die.net/man/1/host

Mattias Åslund

Posted 2013-11-11T18:27:22.950

Reputation: 1 283