How to Perform Reverse DNS Lookups in Linux Terminal Using dig and host

While conventional DNS queries translate human-readable domain names into numerical IP addresses (forward DNS resolution), reverse DNS (rDNS) performs the exact inverse operation. By querying a special pointer record (known as a PTR record), reverse DNS resolves an IPv4 or IPv6 address back into its associated fully qualified domain name (FQDN).

Network engineers, system administrators, and security analysts frequently rely on reverse DNS lookups to verify email server authenticity (fighting spam via SPF and PTR validation), audit traceroute hops, and identify unfamiliar hosts connecting to firewalls. In Linux, the command-line utilities dig and host provide the most reliable, standards-compliant tools to query PTR records.

Understanding PTR Records and in-addr.arpa

Under the hood, reverse DNS does not query raw IP strings directly. Instead, IPv4 addresses are reversed in dotted-decimal notation and appended to the special top-level domain in-addr.arpa. For instance, the reverse lookup domain for 8.8.8.8 is represented as 8.8.8.8.in-addr.arpa.

Similarly, IPv6 reverse records invert individual nibbles (hexadecimal digits) separated by periods and append them to ip6.arpa. Fortunately, modern Linux command-line utilities handle this byte formatting automatically behind the scenes.

Method 1: Performing Reverse Lookups with the dig Command

The dig (Domain Information Grok) utility, bundled inside the bind9-dnsutils package on Ubuntu/Debian and bind-utils on Fedora/RHEL, is the industry standard tool for comprehensive DNS troubleshooting.

Basic Reverse Query with dig -x

To perform an automated reverse lookup for an IPv4 address, pass the -x flag followed by the target IP:

dig -x 8.8.8.8

In the command output, inspect the ANSWER SECTION. You will observe the inverted in-addr.arpa domain querying for a PTR record, returning the resolved host (in this case, dns.google.).

Extracting Clean Short Output with +short

When writing Bash deployment scripts or automating server health checks, you typically only need the resolved domain name without verbose DNS header metadata. Append the +short parameter:

dig -x 1.1.1.1 +short

The output returns solely the canonical pointer record:

one.one.one.one.

Querying Specific Upstream DNS Servers

If you suspect local DNS caching or split-horizon DNS inconsistencies, you can force dig to query a specific external resolver (such as Cloudflare or your internal nameserver) using the @server syntax:

dig @9.9.9.9 -x 8.8.4.4 +short

Reverse Lookup for IPv6 Addresses

The -x flag seamlessly parses standard 128-bit IPv6 addresses, sparing you the manual labour of reconstructing 32 nibbles:

dig -x 2001:4860:4860::8888 +short

Method 2: Performing Quick Reverse Queries with the host Command

If you prefer a concise, human-readable summary without query flags, the host command is an exceptional alternative:

host 8.8.8.8

The terminal immediately returns a clean, plain-English evaluation:

8.8.8.8.in-addr.arpa domain name pointer dns.google.

Querying a Custom Nameserver with host

To specify an alternate resolver with host, simply append the server address at the end of the argument list:

host 8.8.8.8 1.1.1.1

Troubleshooting Missing or Incomplete Reverse DNS Records

If your query returns no ANSWER SECTION or yields an NXDOMAIN response, consider the following diagnostic factors:

  • Delegation Boundaries: Unlike forward DNS domains managed by registrar accounts, reverse DNS ranges are allocated strictly by Internet Service Providers (ISPs) or Regional Internet Registries (RIRs like ARIN, RIPE, or APNIC). The IP owner must explicitly delegate authority for the block.
  • Email Server Impact: Mail transfer agents (like Postfix or Sendmail) frequently reject incoming messages if the connecting IP does not possess a valid PTR record matching its forward A record (FCrDNS / Forward-Confirmed Reverse DNS).
  • Firewall Filtering: Ensure UDP and TCP port 53 traffic is permitted outbound to your upstream resolvers.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.