You want to reverse-map an address to a domain name using dig.
Use digs -x command-line option, which takes an IP address as an option argument. For example:
$ dig -x 126.96.36.199
dig prints the interpreted DNS response message, just as it did in Section 10.10:
; <<>> DiG 9.2.1 <<>> -x 188.8.131.52 ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12896 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 0 ;; QUESTION SECTION: ;184.108.40.206.in-addr.arpa. IN PTR ;; ANSWER SECTION: 220.127.116.11.in-addr.arpa. 21600 IN PTR www.oreilly.com. ;; AUTHORITY SECTION: 146.204.209.in-addr.arpa. 21600 IN NS ns.oreilly.com. 146.204.209.in-addr.arpa. 21600 IN NS ns1.sonic.net. ;; Query time: 62 msec ;; SERVER: 192.168.0.1#53(192.168.0.1) ;; WHEN: Thu Jun 27 20:28:41 2002 ;; MSG SIZE rcvd: 118
The domain name the address maps to is shown in the ANSWER SECTION, as the RDATA of the PTR record (www.oreilly.com, in this case).
If the PTR record reverse-mapping the address is in a zone delegated using the scheme described in RFC 2317 (Section 6.5), you may need to specify the type PTR on the command line, too: older versions of dig send queries for records in any type when you use the -x option. You can tell which variety your dig is by looking at the type of the query in the QUESTION SECTION. The version of dig we used in this recipe was a newer one, which sends an explicit PTR query.
You can also use digs -x option just to build the domain name to look up from the octets of the IP address and specify a different record type on the command line. For example, to look up A records attached to 0.168.192.in-addr.arpa (read RFC 1101 for why youd ever want to do that), you could use:
$ dig -x 192.168.0 a
dig(1); Section 6.5; RFCs 1101 and 2317; "Using dig" in Chapter 12 of DNS and BIND.
BIND Name Server Configuration
BIND Name Server Operations
Delegation and Registration
Interoperability and Upgrading
Resolvers and Programming
Logging and Troubleshooting