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?
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?