8

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.

xhienne
  • 17,075
  • 2
  • 52
  • 68
  • got the host command? – Rui F Ribeiro Aug 02 '17 at 17:09
  • The `host` command from ISC is exactly the sort of _BIND utility_ that the questioner said that xe does not have. (Of course there are the alternative `host` commands from KnotDNS or from the djbwares toolset, so it isn't _solely_ a BIND utility. (-:) – JdeBP Aug 02 '17 at 19:35

2 Answers2

17

Use getent:

$ getent hosts unix.stackexchange.com
151.101.193.69    unix.stackexchange.com  unix.stackexchange.com
xhienne
  • 17,075
  • 2
  • 52
  • 68
1

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.

Patrick Mevzek
  • 3,130
  • 2
  • 20
  • 30
  • 1
    Nice and informative. But docker images dont package systemd as there is no run-level within the image, as well as quite a few oher missing tings that systemd requires. – Inquisitor Shm Aug 03 '17 at 03:28