What is the most concise way to resolve a hostname to a local IP address in Arch Linux?
Asked
Active
Viewed 1.5k times
1
-
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
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,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
-
2There is no `dnsutils` package in Arch, it was replaces by `bind-tools` in June 2015. – Wieland Jul 17 '16 at 18:40