Article 5PW1R How to do local-only DNS lookup?

How to do local-only DNS lookup?

by
boughtonp
from LinuxQuestions.org on (#5PW1R)
When offline, I can use "getent hosts" to read from /etc/hosts and return the expected IP like so:
Code:getent hosts example.com | awk '{print $1}'However, when not offline the above ignores the hosts file and returns the public IP instead. :/

(I've also tried "dig", "delv", "host" but these all bypass the hosts file and don't work at all when offline.)

I want to do a strictly local-only DNS lookup, never causing network traffic under any situation, not even when a record isn't found locally.

It seems I'm going to have to parse /etc/hosts myself - not difficult to do, but I feel like this shouldn't be necessary.

So, does anyone know of an existing standard command that can do this, or some option I've missed on how to make getent always work offline?

latest?d=yIl2AUoC8zA latest?i=jbZmWLiy43M:wuXo6ZN_li0:F7zBnMy latest?i=jbZmWLiy43M:wuXo6ZN_li0:V_sGLiP latest?d=qj6IDK7rITs latest?i=jbZmWLiy43M:wuXo6ZN_li0:gIN9vFwjbZmWLiy43M
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments