Learn more about Russian war crimes in Ukraine.

How does reverse DNS lookup work?

You have an IP address like, and you want to know which domains point to it. I always used to Google “reverse IP”, then use a web service like this one. I assumed these services must have some giant database of all public DNS records in order to invert the query.

That’s not how it works! You can do the same “reverse IP” query yourself using a tool like dig:

$ dig +short PTR

And sure enough, if we ask for the IP for google-public-dns-b.google.com, we get

$ dig +short A google-public-dns-b.google.com

This works because DNS has a PTR record type, which is like the inverse of the A record type. Where there is a record google-public-dns-b.google.com. IN A, there is an equivalent inverse record IN PTR google-public-dns-b.google.com..

Notice the weird notation All IP addresses A.B.C.D are assigned a “domain” D.C.B.A.in-addr.arpa. This hack seems to be necessary because the “left-hand side” of DNS record types are supposed to be domains, not IP addresses.

Because this PTR query is on a separate set of PTR records, and not on the canonical set of A records, there is no guarantee that it will give you an inverse. The PTR records can be inconsistent with the A records.

How does dig look up the “domain” The same as for any other domain name! Traverse the domain name from the root, beginning by asking the root nameservers. We get results like these:

arpa.			          IN	NS	a.root-servers.net.
in-addr.arpa.		    IN	NS	a.in-addr-servers.arpa.
8.in-addr.arpa.		  IN	NS	ns1.Level3.net.
8.8.in-addr.arpa.	  IN	NS	ns1.Level3.net.
4.8.8.in-addr.arpa.	IN	NS	ns1.google.com.

The IP address space is hierarchical, just like the domain name space. But the most-significant digit is on the left of the IP address, unlike the most-significant part of the domain name, which is on the right. This is the reason that the IP address A.B.C.D is reversed when placed into its “domain” D.C.B.A.in-addr-arpa.

The owner of the IP address space 8.8.*.*, i.e., is in control of the domain 8.8.in-addr-arpa. Apparently Google is the owner of 8.8.4.*, i.e. We can explore these ownerships with other tools, but that’s another blog post.

What can computers do? What are the limits of mathematics? And just how busy can a busy beaver be? This year, I’m writing Busy Beavers, a unique interactive book on computability theory. You and I will take a practical and modern approach to answering these questions — or at least learning why some questions are unanswerable!

It’s only $19, and you can get 50% off if you find the discount code ... Not quite. Hackers use the console!

After months of secret toil, I and Andrew Carr released Everyday Data Science, a unique interactive online course! You’ll make the perfect glass of lemonade using Thompson sampling. You’ll lose weight with differential equations. And you might just qualify for the Olympics with a bit of statistics!

It’s $29, but you can get 50% off if you find the discount code ... Not quite. Hackers use the console!

More by Jim

Tagged #programming, #networking. All content copyright James Fisher 2018. This post is not associated with my employer. Found an error? Edit this page.