howtouselinux

4 ways to Check DNS Record with Dig Command in Linux

Table of Contents

The most efficient way to check DNS records in Linux is using dig command. This command will send the DNS query to the name servers listed in the resolver(/etc/resolv.conf). It allows you to query information about various DNS records, including A record, MX record CNAME record etc.

The following commands can be used to check DNS records in Linux.

  • dig dnsrecords.com
  • dig @8.8.8.8 dnsrecords.com
  • dig dnsrecords.com ANY
  • dig dnsrecords.com +short
  • dig dnsrecords.com +trace

 

How to use Dig command

We can use dig name + record type + @dns server to query the DNS info from a DNS server. By default, dig performs a lookup for an A record if no type argument is specified.

dig @server name type

  1. server – the IP address or hostname of the name server to query. It is optional and if we don’t provide a server argument then dig uses the name server listed in /etc/resolv.conf.
  2. name – the name of the resource record that is to be looked up.
  3. record type – the type of query requested by dig. For example, it can be an A record, MX record, SOA record or any other types.

Check DNS A record with Dig command

The A stands for address and this is the most fundamental type of DNS record. A record is used to point a domain or subdomain to an IP address. We can use this command to query A record for a domain name. For example:

$ dig howtouselinux.com
howtouselinux.com. 0 IN A 23.236.62.147

Query DNS PTR record with dig command

A PTR record is well-known as the reverse version of an A record. We can get the PTR record with this command. This is the PTR record for IP address 23.236.62.147.

$ dig -x 23.236.62.147
147.62.236.23.bc.googleusercontent.com.

Query DNS MX record with dig command

A DNS ‘mail exchange’ (MX) record directs email to a mail server. This record can tell us the email server for a domain name. With the following command, we can get the MX record for google.com.

$ dig google.com mx
google.com. 0 IN MX 10 aspmx.l.google.com.
google.com. 0 IN MX 20 alt1.aspmx.l.google.com.
google.com. 0 IN MX 50 alt4.aspmx.l.google.com.
google.com. 0 IN MX 30 alt2.aspmx.l.google.com.
google.com. 0 IN MX 40 alt3.aspmx.l.google.com.

Get DNS records Against a specific DNS server with dig command

Many DNS servers are around the world. To specify a name server against which the query will be executed, use the @ (at) symbol followed by the name server IP address or hostname.

$ dig howtouselinux.com @8.8.8.8
howtouselinux.com. 5 IN A 23.236.62.147

Related Post:

David Cao
David Cao

Hey there! I am David, a Cloud & DevOps Enthusiast and 18 years of experience as a Linux engineer. I work with AWS, Git & GitHub, Linux, Python, Ansible, and Bash. I am a technical blogger and a Software Engineer, enjoy sharing my learning and contributing to open-source.