In a bash, I have an IP like 104.16.117.182
. This is the address of unix.stackexchange.com.
But, from the IP, how can I resolve it to the hostname? Like:
>>> magic 104.16.117.182
you get: unix.stackexchange.com
Any idea?
In a bash, I have an IP like 104.16.117.182
. This is the address of unix.stackexchange.com.
But, from the IP, how can I resolve it to the hostname? Like:
>>> magic 104.16.117.182
you get: unix.stackexchange.com
Any idea?
Reverse records (for IPv4) are stored (backwards) somewhere under the in-addr.arpa
zone, which tools like host
will handily reverse for you, while other tools may need to be fed the reversed IP address and so forth.
% host 8.8.8.8 | awk '{print $NF}'
google-public-dns-a.google.com.
% host 104.16.117.182
Host 182.117.16.104.in-addr.arpa. not found: 3(NXDOMAIN)
% dig +short PTR 4.4.8.8.in-addr.arpa
google-public-dns-b.google.com.
%
Whether appropriate reverse records have been setup, well, maybe you get lucky, maybe you do not.
Over in IPv6istan, you'll probably want a tool (e.g. sipcalc
) that can expand out an IPv6 address instead of typing things out...
% dig +short PTR 8.8.8.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.8.4.0.6.8.4.1.0.0.2.ip6.arpa.
google-public-dns-a.google.com.
%