DNS Resolution Everywhere


Usually at leas one of those is present on any system

  • dig
  • nslookup
  • host

But sometimes the usual suspects don’t work, especially in container-land. After trying them you may try some more involved/unknown things:

getent

Part of glibc, this will probably work on nearly every system.

getent hosts example.org

Or, if you specifically want to query A or AAAA records.

getent ahostsv4 example.org
getent ahostsv6 example.org

Using Python2 Or Python3

Given this depends on glibc it is more of a alternative than another real solution

python3 -c "import socket; print(socket.gethostbyname('example.org'))"
python2 -c "import socket; print(socket.gethostbyname('example.org'))"

See also