-1

This question already has an answer here:

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?

marked as duplicate by Jeff Schaller, chaos, heemayl, Jakuje, Anthon Apr 13 '16 at 19:54

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.

  • 2
    It's the other way around though. – Jakob Lenfers Apr 13 '16 at 15:25
  • yes, @JeffSchaller, I want the other way. I really have read this question before post. – Pedro Henrique Pedro Apr 13 '16 at 15:49
  • nslookup, host, and dig (with -x) from the other Q all (attempt) reverse resolution. In this particular case, the IP's for unix.stackexchange.com do not have reverses, as thrig pointed out. – Jeff Schaller Apr 13 '16 at 15:57
  • BTW, this question has nothing to do with bash. You're looking for a command, and that command will run a program, and so will work equally well in any shell — commands like this aren't built into shells. – Scott Apr 13 '16 at 18:36
1

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.
% 
  • It din't work for me yet. When I tried the google (8.8.8.8) I have no problem. But to get the hostname of stackexchange don't work. But if I copy and paste the IP (104.16.117.182) in my browser I don't get to stackexchange. The problem now is the cloudflare? – Pedro Henrique Pedro Apr 13 '16 at 16:01
  • If there's no reverse record, then there's no reverse record. They're not always set these days, especially for things like load balancers that probably host all sorts of different domains, or cloud services where there's no API to fiddle around with records in the appropriate reverse zone. – thrig Apr 13 '16 at 17:14

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