What is the most concise way to resolve a hostname to a local IP address in Arch Linux?
Asked
Active
Viewed 1.7k times
1
2 Answers
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
-
2There is no
dnsutils
package in Arch, it was replaces bybind-tools
in June 2015. – Wieland Jul 17 '16 at 18:40
host
command. – Kusalananda Jul 17 '16 at 18:27dnsutils
(I googled it). – Kusalananda Jul 17 '16 at 18:31