I want to test in a script whether a hostname resolves to something other than 127.0.0.1 as a pre-flight test for an install script. The tools I know (dig, nslookup) specifically query DNS. In my situation a correct entry in /etc/hosts is a valid configuration. So the question is:
Is there a dig-like tool, ideally already on the system, that does the full name-resolution process via nsswitch.conf, like (for example) ping does?
dig my-test-server-that-only-exists-in-etc-hosts
returns NXDOMAIN.
Best Answer
This already has an answer on SU:
Bash: lookup an IP for a host name, including /etc/hosts in search
Basically, you use
where host_name can either be an entry in your
/etc/hosts
, in which case it will resolve to that, or a host that your DNS can resolve.Quoting the
getent(1)
man page: