1

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

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Paradox
  • 722
  • 2
  • 8
  • 25

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,353
  • 3
  • 28
  • 31
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
  • 320,670
  • 36
  • 633
  • 936