The commands dig and host should be what you're looking for ;)

On *nix systems, you can use this command:

dig -x [address]

Alternatively, you can add +short at the end of the dig command to output only the DNS result.

There's also nslookup on both *nix and Windows systems for reverse DNS requests.

Answer from Marc-Andre R. on serverfault.com
🌐
nixCraft
cyberciti.biz › nixcraft › howto › linux › how to test or check reverse dns on a linux / unix
How To Test or Check Reverse DNS on a Linux / Unix - nixCraft
January 31, 2025 - In this example output, IP 75.126.43.235 is reverse mapped to cyberciti.org. Here is another reverse lookups done using dig command: $ dig -x ip-address-here $ dig -x 75.126.153.206 Sample outputs:
🌐
Linux Hint
linuxhint.com › reverse-dns-lookup-in-linux
Do a Reverse DNS Lookup in Linux – Linux Hint
In the non-interactive mode, it only shows the name and relevant requested details for a domain. Use the following nslookup command to display the information about the given IP address: ... The reverse DNS lookup is a straightforward method to ensure that the IP address does belong to the ...
🌐
nixCraft
cyberciti.biz › nixcraft › howto › freebsd › reverse nslookup command
Reverse nslookup Command - nixCraft
September 12, 2024 - Explains how to use reverse nslookup command under UNIX/Linux or MS-Windows OS to find out an IP address to resolve a hostname/domain name
🌐
FOSS Linux
fosslinux.com › home › beginner's guide › top 3 ways to lookup reverse dns on linux
Top 3 ways to lookup reverse DNS in Linux | FOSS Linux
April 13, 2020 - In this tutorial, we will show you how to perform a reverse DNS lookup using one of the following methods: ... Before starting, let’s check first how to issue a forward DNS lookup using the dig command as follows: ... As you can notice, using ...
Find elsewhere
🌐
Blogger
linuxcommando.blogspot.com › 2008 › 07 › how-to-do-reverse-dns-lookup.html
Linux Commando: How to do reverse DNS lookup
67 IN A 199.232.41.10 The IP address is displayed in the A record, and is 199.232.41.10. The +noall, +answer combination basically tells dig to only report the answer of the DNS query and skip the rest of the output. You can also use the dig command with the -x option to do a reverse DNS lookup.
Top answer
1 of 4
10

xargs provides an optin --arg-file. With -L1 option to treat each line as argument, the simplest command we can make is as follows

$ xargs -L1 --arg-file=ip-addr.txt dig +short -x
google-public-dns-a.google.com.
resolver2.opendns.com.

If it's necessary to display the IP address next to the resolved domain, we can also do:

$ xargs -L1 --arg-file=ip-addr.txt sh -c 'printf "%s: " "$1"; dig +short -x "$1"' sh
8.8.8.8: google-public-dns-a.google.com.
208.67.220.220: resolver2.opendns.com.

Of course, xargs is an extra process. What if we wanted to only use shell and dig ? With bash version 4 and over, we can use mapfile or readarray to get lines of the text file into array, and then process items in a loop:

$ mapfile -t -d $'\n' < ip-addr.txt
$ for i in "${MAPFILE[@]}" ; do printf "%s:" "$i"; dig +short -x "$i"; done
8.8.8.8:google-public-dns-a.google.com.
208.67.220.220:resolver2.opendns.com.

If the IP addresses are few and don't require a long text file, POSIXly, we could use set to define values as positional parameters:

$ set -- 8.8.8.8 208.67.220.220
$ for i ; do printf "%s:" "$i"; dig +short -x "$i"; done
8.8.8.8:google-public-dns-a.google.com.
208.67.220.220:resolver2.opendns.com.

We can also use dig -x $IP_ADDRESS +short in a script like so:

#!/bin/bash
export LC_ALL=C
# without specifying 'in' part, bourne-like shells default
# to iterating over positional parameters
for item
do
     domain=$(dig -x "$item"  +short)
     # this logic can also be reversed with
     # [ "x$domain" = "x" ] && echo "empty" || echo "$domain"
     if [ -n "$domain"  ] ;
     then
         echo "$domain"
     else
         echo "$item" result is NULL
     fi
done

Demo of sample usage(all ip addresses given as space separeted):

$ ./reverse_dns_lookup.sh 8.8.8.8 74.125.193.94 151.101.193.69                 
google-public-dns-a.google.com.
ig-in-f94.1e100.net.
151.101.193.69 result is NULL

As you can see , in the last example our DNS server didn't find domain for the ip address we gave it. In such case we can use a different DNS server, for instance open_dns with dig @208.67.220.220 $IP_ADDRESS +short

In the demo above, the ip addresses are provided on command line, like ./reverse_dns_lookup.sh ADDRESS1 ADDRESS2 ADDRESS2 but you also can use a file for that, like so:

$ cat ip_addresses.txt |  xargs ./reverse_dns_lookup.sh                          <
google-public-dns-a.google.com.
resolver2.opendns.com.
192.30.253.112 result is NULL

Alternative script version:

Here's alternative version of the script that prints the AUTHORITY section from dig's output. This may be much better and more reliable than just +short version. NOTE: this uses 8.8.8.8 , which is Google's public DNS. Use a different server if you feel necessary.

#!/bin/bash
export LC_ALL=C
for item
do
 domain=$(dig @8.8.8.8  -x "$item" +noall +authority +answer)
 if [ -n "$domain"  ] ;
 then
     echo "$domain"
 else
     echo "$item" result is NULL
 fi
done

Demo:

$ cat ip_addresses.txt |  xargs ./reverse_dns_lookup.sh 

; <<>> DiG 9.10.3-P4-Ubuntu <<>> @8.8.8.8 -x 8.8.8.8 +noall +authority +answer
; (1 server found)
;; global options: +cmd
8.8.8.8.in-addr.arpa.   21390   IN  PTR google-public-dns-a.google.com.

; <<>> DiG 9.10.3-P4-Ubuntu <<>> @8.8.8.8 -x 208.67.220.220 +noall +authority +answer
; (1 server found)
;; global options: +cmd
220.220.67.208.in-addr.arpa. 6674 IN    PTR resolver2.opendns.com.

; <<>> DiG 9.10.3-P4-Ubuntu <<>> @8.8.8.8 -x 192.30.253.112 +noall +authority +answer
; (1 server found)
;; global options: +cmd
253.30.192.in-addr.arpa. 10 IN  SOA ns1.p16.dynect.net. ops.github.com. 6 3600 600 604800 60
2 of 4
4

Here is a quick and dirty one liner: Contents of ip-addresses.txt:

$ cat ip-addresses.txt
    1.2.3.4
    1.1.1.1
    222.222.222.222
    23.12.34.56
    8.8.8.8
    208.67.222.220

Replace txt with your file that contains addresses, separated by newlines:

$ cat ip-addresses.txt | xargs -I % bash -c 'echo "%:$(dig -x % +short)"' >> dig-output.txt

If you append to dig-output.txt like above, contents of that file will be like below, if reverse DNS lookup is successfull, IP:NAME, if not, IP:(NULL)

$ cat dig-output.txt
1.2.3.4:
1.1.1.1:
222.222.222.222:
23.12.34.56:a23-12-34-56.deploy.static.akamaitechnologies.com.
8.8.8.8:google-public-dns-a.google.com.
208.67.222.220:resolver3.opendns.com.

If IP addresses are coming from another process, you can directly pipe to xargs.

Edit: If you must have a word such as null (inspired by @Serg) in case of a lookup failure, you can use the command below:

$ cat ip-addresses.txt | xargs -I % bash -c '{ query=$(dig -x % +short); if [ -z $query ]; then query=null;fi; echo %:$query; }'
  • cat ip-addresses.txt # Print IP addresses to STDOUT. If you don't want to cat from file, you can directly pipe from another process like command | xargs ...
  • xargs -I % bash -c # Take each line from left of pipe, use % as placeholder, run bash command that follows within single quotes
  • dig IP address that comes from placeholder % by xargs, assign to variable query. If result happens to be null (zero length), assign string 'null' word to query variable, then print as IP:result

Demo:

$ cat ip-addresses.txt | xargs -I % bash -c '{ query=$(dig -x % +short); if [ -z $query ]; then query=null;fi; echo %:$query; }'
1.2.3.4:null
1.1.1.1:null
222.222.222.222:null
23.12.34.56:a23-12-34-56.deploy.static.akamaitechnologies.com.
8.8.8.8:google-public-dns-a.google.com.
208.67.222.220:resolver3.opendns.com.
🌐
DNS Checker
dnschecker.org › reverse-dns.php
Reverse IP Lookup - Reverse DNS Lookup
If you are using Linux or MAC OS, run dig -x IP_address on Linux's console terminal or MacOs's terminal. Note: Replace the IP_address with your domain's IP address. Just enter the IP address and click on the "Submit" button.
🌐
WhatIsMyIP.com®
whatismyip.com › reverse-dns-lookup
Reverse DNS Lookup | Reverse IP Lookup Tool - WhatIsMyIP.com®
For a reverse IP lookup in the Linux system, users can use three different commands to perform the reverse DNS process: the dig command, the host command, and the nslookup command.
🌐
Web Hosting Geeks
webhostinggeeks.com › home › dns › how to check or test reverse dns on linux and windows
How to Check or Test Reverse DNS on Linux and Windows | Linux Tutorials for Beginners
April 28, 2023 - Type the following command and replace “IP_ADDRESS” with the actual IP address you want to check: ... Press Enter, and the terminal will display the domain name associated with the IP address, if the PTR record is correctly configured. dig ...
🌐
What's My DNS
whatsmydns.net › reverse-dns-lookup
Reverse DNS Lookup
Fortunately nslookup makes the process of reverse DNS lookups easy and will automatically perform the PTR record conversion into the correct .arpa domain for you. To find the reverse DNS entry for the IP address 192.0.2.1 using your systems built in DNS resolver: ... To find the reverse DNS entry for the IP address 192.0.2.1 using the specified DNS resolver 1.1.1.1: ... Linux operating systems like Ubuntu, CentOS ...
🌐
Baeldung
baeldung.com › home › networking › network monitoring › checking ptr records using the command line
Checking PTR Records Using the Command Line | Baeldung on Linux
March 18, 2024 - For IPv6 records, the IP address is reversed and split into chunks of four bits (one hexadecimal digit) each, separated by a dot. The namespace used is ip6.arpa instead of in-addr.arpa. So, for an IP 4002:5003:6004:7005:8006:9007:a008:b009, the PTR record would be 9.0.0.b.8.0.0.a.7.0.0.9.6.0.0.8.5.0.0.7.4.0.0.6.3.0.0.5.2.0.0.4.ip6.arpa.
🌐
How to Use Linux
howtouselinux.com › home › 2 ways to perform reverse dns lookups in linux
2 Ways to Perform Reverse DNS lookups in Linux - howtouselinux
October 9, 2025 - Reverse DNS lookup, also known as rDNS, is used to determine or resolve the IP address associated with the domain name. It is simply an entry that resolves an IP address back to a hostname. It is also called PTR record in DNS. Purpose of reverse DNS lookups Reverse DNS lookups are commonly ...
🌐
LinuxVox
linuxvox.com › blog › linux-reverse-lookup
Linux Reverse Lookup: A Comprehensive Guide — linuxvox.com
The output will show the domain name associated with this IP address if it exists. The dig command is a more powerful and flexible DNS lookup utility. To perform a reverse lookup using dig, you can use the following command:
🌐
2DayGeek
2daygeek.com › home › how to check reverse dns (rdns) lookup in linux?
How To Check Reverse DNS (rDNS) Lookup In Linux? | 2DayGeek
July 28, 2019 - It is normally used to convert names to IP addresses and vice versa. nslookup Command: Nslookup is a program to query Internet domain name servers. dig Command: Dig stands for domain information groper is a flexible tool for interrogating DNS ...
🌐
Perishable Press
perishablepress.com › cli-forward-reverse-lookup
CLI Forward-Reverse Lookup | Perishable Press
Here we are using the host command to perform a reverse DNS lookup for the IP address of my own server, 64.207.179.70.