Introduction
Domain Information Groper (dig) is a Linux utility tool that queries Domain Name System (DNS) information for a particular hostname or IP Address. By usage, the dig utility allows you to:
Perform DNS lookup operations and verify available DNS settings. For example, check name servers (NS), A, and mail exchange records (MX) for a target domain name
Troubleshoot networking and record routing problems
Trace a server's DNS path
By functionality, dig checks IP addresses mapped to domain names and any additional records associated with the domain. This guide explains how to look up DNS records using the dig CLI Tool on a Linux server.
Prerequisites
Before you start:
Switch to the sudo user account
# su example_user
Install the dig CLI Tool
The dig utility works on all Linux distributions, but the installation process differs per system. It's part of a larger dnsutils package that additionally enables several DNS client utilities like nsupdate and nslookup. Install the dig CLI tool as described in the following steps
Install the
dnsutilspackage on your serverOn Ubuntu/Debian:
$ sudo apt install dnsutils -yCentOS 7:
$ sudo yum install bind-utils -yFedora/Rocky Linux:
$ sudo dnf install bind-utils -yArch Linux:
$ sudo pacman -Sy dnsutilsWhen installed, verify the available
digversion$ dig -vOutput:
DiG 9.18.12...
The dig Usage Syntax
The dig utility uses the following command syntax to fetch DNS records
$ dig @DNS_SERVER NAME TYPE QUERY_OPTIONS
Below are the available command options:
@DNS_SERVER: Defines the name or IP address of the server that performs the query. In short, it sets the DNS database that responds when you submit a query. For example, a hostname, IPv4, or IPv6 addressNAME: Defines the resource you want to know more about. For instance, to perform a DNS lookup for theexample.comdomain, define the domain name when running thedigutilityTYPE: The type of query to perform. For example,ANY,A,MX, orNSrecords. When theTYPEoption is not used, thedigcommand performs a lookup for theArecord. Below are the most common DNS record query types you can perform using thedigcommand:A: Links a domain name to an IP address. This is the main query performed by thedigcommandNS: Returns the domain name's authoritative nameserver. This record displays the nameserver hosting the domain's DNS recordsMX: Returns a domain's mail server recordsCNAME: Also known as Canonical Name, it maps one domain name to another and it's often used to resolve domain variations. By usage, it shows that one domain name is an alias for another domain. For examplewww.example.comis a CNAME toexample.comTXT: Returns the email server verification recordsANY: Returns all records of a query
QUERY_OPTIONS: Affects howdigperforms and displays the DNS lookup results. Options are relevant when you want to limit the query answers, timeout, and retry strategies. Below are the sample query options:+short: Displays short query outputs+noall: Clears all default output flags+trace: Traces the path a query takes in a hierarchical manner+cmd: Removes comments from the output
Perform DNS Lookup using the dig Command
To test and verify how the dig utility tool works, perform sample DNS look-up operations as described below.
Query the
example.comdomain A record$ dig example.com AOutput:
; <<>> DiG 9.18.12-0ubuntu0.22.04.2-Ubuntu <<>> example.com A ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57779 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 65494 ;; QUESTION SECTION: ;example.com. IN A ;; ANSWER SECTION: example.com. 63083 IN A 93.184.216.34 ;; Query time: 0 msec ;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP) ;; WHEN: Wed Aug 02 10:02:59 UTC 2023 ;; MSG SIZE rcvd: 56Repeat the above query, but use the
+shortoption to return only the most relevant information$ dig example.com +shortOutput:
93.184.216.34Query the domain nameserver (
NS) records. Clear the default outputs using+noall, and display ashortresponse$ dig example.com NS +noall +shortOutput:
a.iana-servers.net. b.iana-servers.net.As displayed in the output, the query returns two nameserver records. This is because a domain name hosts at least two
NSrecords for high availability and load balancing. The nameserver's redundancy setting ensures that DNS queries are successful even when some servers are offline.Query the domain's
MXrecords$ dig example.com MX +noall +shortOutput:
0 .As displayed in the above output, the domain
example.comdoes not have any MX records. When you query a domain with MX entries, the records display in your outputUsing the
+traceoption, find theexample.comDNS path$ dig example.com +trace +noall +shortOutput:
NS m.root-servers.net. from server 127.0.0.53 in 0 ms. NS k.root-servers.net. from server 127.0.0.53 in 0 ms. NS b.root-servers.net. from server 127.0.0.53 in 0 ms. NS i.root-servers.net. from server 127.0.0.53 in 0 ms. NS j.root-servers.net. from server 127.0.0.53 in 0 ms. NS f.root-servers.net. from server 127.0.0.53 in 0 ms. NS a.root-servers.net. from server 127.0.0.53 in 0 ms. NS e.root-servers.net. from server 127.0.0.53 in 0 ms. NS c.root-servers.net. from server 127.0.0.53 in 0 ms. NS g.root-servers.net. from server 127.0.0.53 in 0 ms. NS l.root-servers.net. from server 127.0.0.53 in 0 ms. NS d.root-servers.net. from server 127.0.0.53 in 0 ms. NS h.root-servers.net. from server 127.0.0.53 in 0 ms. A 93.184.216.34 from server 2001:500:8f::53 in 80 ms. RRSIG A 13 2 86400 20230811193456 20230721104039 2061 example.com. Ujxl1F4YCnUNlRD2kWfq1XeT59rSFtELq/yLZLzkfrfmWcj5xiPO4qRH k1KKO3k3kiKwO24nhR0AYuABZq/CeQ== from server 2001:500:8f::53 in 80 ms.To redirect a
digquery to a specific DNS server and display a short answer with no comments, use the+nocmd,+noall,+answeroptions as below$ dig @a.iana-servers.net example.com +nocmd +noall +answerOutput:
example.com. 86400 IN A 93.184.216.34
Conclusion
In this guide, you installed and used the dig utility tool to look up domain DNS records. The dig utility offers multiple options you can use to enhance your DNS lookup operations. run the dig -h command to view all available options depending on your query needs. When used effectively, the dig command allows you to quickly detect and resolve major DNS issues when working with production cloud servers.
Next Steps
To use other utility tools on your RCS Cloud Server. Visit the following resources: