0

This question already has an answer here:

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

marked as duplicate by Jeff Schaller, chaos, dr01, Gilles, Stephen Harris Jul 17 '16 at 22:30

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Using the host command. – Kusalananda Jul 17 '16 at 18:27
  • I coulnd't find that in the Arch Repo or AUR, do you know what package this comes with? – Paradox Jul 17 '16 at 18:30
  • dnsutils (I googled it). – Kusalananda Jul 17 '16 at 18:31
  • Thanks. You are welcome to add an answer so I can close this question – Paradox Jul 17 '16 at 18:32
  • I had seen that originally but found it to be the opposite of what I am looking to do. – Paradox Jul 17 '16 at 18:40
6

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.
1

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.

  • 2
    There is no dnsutils package in Arch, it was replaces by bind-tools in June 2015. – Wieland Jul 17 '16 at 18:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.