How to get remote host DNS address from a super-slim host (docker) without ping or bind-utils?

How do I get a remote host IP address if I don’t have ping, and don’t have any bind utilities like dig, nslookup, etc?

I need an answer that does not include ‘install X’ or ‘use sidecar container’. I am looking for something that relies on nothing more than bash and the basic shell commands.

Asked By: Inquisitor Shm

||

Use getent:

$ getent hosts unix.stackexchange.com
151.101.193.69    unix.stackexchange.com  unix.stackexchange.com
Answered By: xhienne

On a “modern” system, you can use systemd-resolve.

From its man page:

systemd-resolve may be used to resolve domain names, IPv4 and IPv6
addresses, DNS resource records and services with the
systemd-resolved.service(8) resolver service. By
default, the specified list of parameters will be resolved as hostnames, retrieving their IPv4 and IPv6 addresses. If the parameters
specified are formatted as IPv4 or
IPv6 operation the reverse operation is done, and a hostname is retrieved for the specified addresses.

It will do DNS, whereas getent, depending on nsswitch.conf may not even do DNS queries.
You can also pass a --type option to have access to any kind of DNS record type.

Answered By: Patrick Mevzek
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.