dig Command in Linux with Useful Examples
Abstract: this records tells system the IP address of server hosting that website. dig +nocmd tecadmin.net A +noall +answerYou can also specify +nocmd option af
dig stands for Domain Information Groper, is a command line network tool for gathering domain name server information. The dig command is another powerful tool similar to nslookup for diagnosing dns related problems.
We can use dig command to query various dns servers to fetch records like address record, CNAME, TXT, Mail exchange records etc… I also found an useful website showmydns.net to search dns records from multiple locations world wide.
This guide explains you to how to use Linux dig
command line utility with practical examples.
The dig utility is available under default repositories on most of the Unix/Linux operating systems. On Debian based systems dig command is available under dnsutils
package. The Redhat based systems dig command is available under bind-utils
rpm package.
Syntax:
A basic and frequently used dig command syntax is like below:
dig [@server] name [type]
Dig Version:
Use -v option with dig command to display version of dig on your system.
dig -v
DiG 9.11.3-1ubuntu1.13-Ubuntu
Dig Command Line Options and Examples
Here is the frequently used command line options and example’s of dig command.
1. Basic Dig CommandA basic dig command accept domain name as command line parameter and prints Address record.
dig tecadmin.net
Output:
; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> tecadmin.net ;; global options: +cmd ;; Got answer: ;; ->>HEADER<In the result ANSWER SECTION: contains the main information you have requested. You can ignore other parts of the output which have other details about query you made.
2. Query With Specific DNS ServerThe default dig command queries to dns server configured on your system. For example, the Linux systems keep default DNS entry in /etc/resolv.conf.
You can overwrite the default DNS to query by passing the DNS server as an command line parameter. The DNS IP must be start with @ symbol.
3. Print Short Answerdig @8.8.8.8 tecadmin.net
Use
+short
command line option to print result in short form. This is basically useful with the shell scripting and other automation tasks.4. Print Detailed but Specific Resultdig tecadmin.net +short
Output: 172.67.134.5 104.28.16.96 104.28.17.96Use
+noall
with+answer
to print detailed information but specific. This will print only answer section including few more details as a result.dig tecadmin.net +noall +answer
Output: ; <<>> DiG 9.10.3-P4-Ubuntu <<>> tecadmin.net +noall +answer ;; global options: +cmd tecadmin.net. 51 IN A 172.67.134.5 tecadmin.net. 51 IN A 104.28.17.96 tecadmin.net. 51 IN A 104.28.16.96You can also specify
+nocmd
option after dig command to print more specific answer section only.How to Search Specific Records with dig Commanddig +nocmd tecadmin.net +noall +answer
Output: tecadmin.net. 284 IN A 104.28.16.96 tecadmin.net. 284 IN A 104.28.17.96 tecadmin.net. 284 IN A 172.67.134.5Next, query the specific DNS records with dig command.
Set Options As Default
- Query Address (A) Record - A DNS Address (A) records is used to bind a domain name to an IP address. In simple worlds, when a user access a website, this records tells system the IP address of server hosting that website.
dig +nocmd tecadmin.net A +noall +answer
Output: tecadmin.net. 129 IN A 104.28.16.96 tecadmin.net. 129 IN A 104.28.17.96 tecadmin.net. 129 IN A 172.67.134.5- Query NS Record - Use the NS option to get a list of authoritative DNS servers for a domain name.
dig +nocmd tecadmin.net NS +noall +answer
Output: tecadmin.net. 21599 IN NS alec.ns.cloudflare.com. tecadmin.net. 21599 IN NS athena.ns.cloudflare.com.- Query MX Record - A MX record (mail exchanger) is used to specify the mail server responsible for accepting email messages on behalf of a domain name.
dig +nocmd tecadmin.net MX +noall +answer
Output: tecadmin.net. 299 IN MX 0 dc-75c7d428c907.tecadmin.net.- Query TXT Record - A TXT record is multi purpose record used for associating arbitary text information with a domain name. Generally, we use this record for domain ownership verification, email security records like SPF, DKIM, and DMARC etc.
dig +nocmd tecadmin.net TXT +noall +answer
Output: tecadmin.net. 299 IN TXT "google-site-verification=" tecadmin.net. 299 IN TXT "v=spf1 include:spf.mandrillapp.com ?all"- Query ALL Records
You can also use option
ALL
to fetch all dns records for a domain.dig +nocmd tecadmin.net ALL +noall +answer
In the above tutorial, you have used multiple command line options to customize results like
+nocmd, +noall, +answer
etc. But you have to write options on command line every time.You can also create a .digrc file in home directory to auto apply each time your make dig query.
cat ~/.digrc
+nocmd +noall +answerThe next time you run dig will default use above specified options.
dig tecadmin.net
Output:
tecadmin.net. 104 IN A 104.28.16.96 tecadmin.net. 104 IN A 172.67.134.5 tecadmin.net. 104 IN A 104.28.17.96ConclusionIn this tutorial, you have learned the uses of dig command with various options and examples. You can also try web applications like showmydns.net to query dns records from multiple locations world wide. which is useful to check dns propagation while adding or updating dns records.