1

What is the most concise way to resolve a hostname to a local IP address in Arch Linux?

Paradox
  • 744

2 Answers2

8

You can use either host or nslookup from bind-tools:

$ host 172.217.19.195
195.19.217.172.in-addr.arpa domain name pointer fra02s21-in-f3.1e100.net.


$ nslookup 172.217.19.195
Server:     192.168.2.1
Address:    192.168.2.1#53

Non-authoritative answer:
195.19.217.172.in-addr.arpa name = fra02s21-in-f3.1e100.net.
Wieland
  • 6,489
2

The host utility will return a string containing the resolved host name:

$ host 8.8.8.8
8.8.8.8.in-addr.arpa domain name pointer google-public-dns-a.google.com.

This ought to be fairly easy to parse in any shell script. If the host name lookup fails, host exits with a non-zero exit status:

$ if ! host 8.8.8.1 2>/dev/null; then echo "lookup failed"; fi
lookup failed

This utility is part of the bind-tools package in Arch Linux.

Kusalananda
  • 333,661