How To Check DNS Records for a Domain
To check DNS records for a domain from the command line, one can use either the dig
or nslookup
command.
The nslookup
command is available by default on all operating systems (Windows, macOS, and Linux). The dig
command is not pre-installed on Windows but is available as part of the BIND tools package.
In this tutorial, we first look at the dig command followed by nslookup.
The dig command
DIG (short for Domain Information Groper) is by far the most widely used DNS lookup utility among system administrators.
How to Install DIG on WindowsThe basic syntax for the dig
command is as follows:
dig domain_name
The dig
command, without any options, returns the A record (IPv4 address) for a domain name. The following screenshot shows the sample output of a dig
command.
The answer section contains the actual response to the lookup. In the above example, it is the IPv4 Address (A record) for the domain.
Use the +short
option to only output the answer data:
dig example.com +short
The server that answered your query is the name server configured on your local computer. However, you can specify which server to query using @nameserver
, as shown in the following example:
dig example.com @8.8.8.8
To reverse-look-up IP addresses, use the -x
option:
Looking Up Different Record Types
By default, dig returns the A record. But you can look up any record type by specifying the record type. For example, the following command query for the MX
record (mail server):
dig mx example.com
The following are the record types you can check with the dig
(and nslookup
) command:
A | IPv4 address record is the IPv4 address associated with the domain name. |
AAAA | IPv6 address record is the IPv6 address associated with the domain name. |
MX | Mail exchanger. |
NS | Name Servers that are authoritative for that domain name. |
SOA | Domain start of authority. |
TXT | The TXT record. |
SRV | Service Records. |
The nslookup command
The nslookup
command comes pre-installed on all major operating systems. Therefore, you can always rely on nslookup
.
The general command-line syntax is as follows:
nslookup domain_name
The nslookup
command, without any options, returns the A
record and AAAA
record for a domain name. The following screenshot shows the sample output of a nslookup
command.
Like with the dig
command, the answer section contains the actual response. The first two lines show information about the DNS server that answered.
To query a specific DNS server, provide the name or IP address of the nameserver after the domain name.
nslookup domain_name nameserver
The following screenshot shows an example:
Nslookup allows us to query it for different record types with the -type
option. The following example shows the usage of nslookup to find the mail server of a domain:
nslookup -type=mx example.com
Record types you can check with nslookup are identical to the record types in DIG.
Authoritative Versus Non Authoritative Answers
If the answer states Non-authoritative, that means the DNS server that returned the answer is not the server responsible for handling the DNS for that domain name.
You can find the authoritative nameserver of a domain by querying the NS
record type:
nslookup -type=ns example.com
An authoritative server is a DNS server that handles the DNS records of the domain. Usually, there are at least two authoritative nameservers for a domain name.