Dig stands for Domain Information Groper. Dig is used to interrogate DNS servers. It has a lot of features to interact with and use DNS servers. In this tutorial, we will look at popular and useful dig command usages. Most of the system and network administrators use dig to debug DNS related issues.
dig Command Help
Help information about dig
command can be listed with the -h
option.
$ dig -h

dig Command Man Page
Detailed help information can be found with man
command like below.
$ man dig

dig Command Syntax
We will use dig
command with the following syntax.
dig @server name type
OR
dig [@global-server] [domain] [q-type] [q-class] {q-opt}
{global-d-opt} host [@local-server] {local-d-opt}
[ host [@local-server] {local-d-opt} [...]]
Get IP Address of Given Domain Name
Dig is mostly used without parameter to get the IP address of the provided DNS name. The default system provided DNS server will be used to DNS resolution.
$ dig poftut.com

Show Only IP Address Of Given Domain
As we see previous example dig will provide a lot of supportive information. This information may be not needed.
$ dig poftut.com +nocomments +noquestion +noauthority +noadditional +nostats

Show Only IP Address
Another useful feature is only printing the IP address. There will be no other information other than IPv4. For these operations +short
parameter can be used.
$ dig poftut.com +short
Show Only IPv4 Address For Given Domain Name
By default all IP address versions IPv4 and IPv6 will be printed. This can be unnecessary in some situations. The printed IP address version can be specified with -4
parameter.
$ dig -4 poftut.com

Show Only IPv6 Address Of Given Domain
As like the previous example, we can only show IPv6 address with the -6
parameter like below.
$ dig -6 poftut.com
Query MX Records of Given Domain
Mail servers can be expressed in DNS servers with the MX records. MX stands for Mail Exchanger. MX records specified the Domain name related mail server IP address. This mail server accepts mail with SMTP protocol from senders.
$ dig poftut.com MX

Query NS Records of Given Domain
There are root DNS servers in the internet world. But these servers do not provide all DNS records all domain names. They just show the Name Server of the query domain name. Those are called Name Servers. Dig can be list Name Servers with NS
$ dig poftut.com NS

Query TXT Records
TXT is short for text. These records are used informal generally human-readable information about the domain name. Keep in mind that this can be some times a security problem.
$ dig poftut.com TXT

Query SOA Records of Given Domain
SOA records are named as authority records. SOA records provide information about the primary name server, email of the domain administrator, domain serial number and some timers related refreshing zone. SOA records can be listed with SOA
parameter.
$ dig poftut.com SOA

Query All DNS Records Types of Given Domain Name
All DNS server records can be listed with ANY
parameter.
$ dig poftut.com ANY

Reverse Lookup of Given Domain
One of the most useful features of dig is reverse DNS lookup. Up to now, we have resolved domain names to the IP addresses. Some times resolving IP addresses into domain names can be useful. This can be done with -x
parameter.
$ dig -x 45.79.133.118

Set Specific DNS Server for dig Query
While querying different types of DNS records by default system provided DNS server is used. This may not be useful in some situations or we may want to test different DNS servers than default ones. The @
sign will be used to specify a specific DNS server.
$ dig @8.8.8.8 poftut.com

Multiple DNS Look-up with dig Command
Generally, an only a single domain name is queried with dig. But there are some times we may want to query multiple domain names in a single command. This can be done like below.
$ dig poftut.com google.com

Bulk DNS Look-up with dig Command
If there are multiple domain names to query these domain names can be provided with a file. Our file name is domains.txt
and its content is like below.
poftut.com google.com
and the command
$ dig -f domains.txt

Trace DNS Path
As we know the DNS system of internetworks as hierarchical manner. When we use dig to resolve some domain name this query is handled by multiple DNS servers in a row. These DNS servers process can be traced with +trace
parameter.
$ dig poftut.com +trace

Set Default Dig Options
The default usage parameter of dig can be made permanent and provided by default without issuing them every time. .digrc
is the file that holds the configuration.
$ echo "+short" > .digrc
1 thought on “Linux Dig Command Tutorial With Examples”