The dig
command is a powerful DNS lookup utility used to query DNS servers and retrieve information about domain name resolutions. It stands for "Domain Information Groper" and is part of the BIND (Berkeley Internet Name Domain) suite of tools. dig
is commonly used by network administrators and others who need to troubleshoot DNS issues or perform DNS queries.
dig [@server] [name] [type] [options]
@server
: The DNS server to query (optional). If not specified, the default DNS server configured in the system will be used.name
: The domain name to query.type
: The type of DNS record to query (e.g., A, AAAA, MX, TXT, etc.). If not specified, the default is A.options
: Additional command-line options to control the behavior ofdig
.
A
: Address record, returns an IPv4 address.AAAA
: IPv6 address record, returns an IPv6 address.CNAME
: Canonical name record, alias of one name to another.MX
: Mail exchange record, specifies the mail server for the domain.NS
: Name server record, lists the authoritative DNS servers for the domain.TXT
: Text record, often used for domain verification and other purposes.SOA
: Start of authority record, provides information about the DNS zone.PTR
: Pointer record, used for reverse DNS lookups.
-
Basic Query
To query the A record for
example.com
:dig example.com
-
Query a Specific DNS Server
To query the DNS server at
8.8.8.8
for the A record ofexample.com
:dig @8.8.8.8 example.com
-
Query for a Specific Record Type
To query the MX records for
example.com
:dig example.com MX
-
Query with Additional Options
To query
example.com
and include detailed output:dig +noall +answer example.com
+noall
: Suppresses all output except for what is specifically requested.+answer
: Displays the answer section of the query.
-
Reverse DNS Lookup
To perform a reverse DNS lookup for the IP address
192.0.2.1
:dig -x 192.0.2.1
When you've recently updated your DNS records, you can use dig
to check if the changes have propagated to different DNS servers:
dig @8.8.8.8 example.com
dig @1.1.1.1 example.com
This queries Google's and Cloudflare's public DNS servers, respectively.
To get information about the authoritative DNS servers and zone details:
dig example.com SOA
To list the authoritative name servers for a domain:
dig example.com NS
- Detailed Output: Provides detailed information about DNS queries and responses, which is useful for troubleshooting.
- Flexibility: Can query different types of records and specify different DNS servers.
- Scripting: Output can be parsed and used in scripts for automated DNS checks and monitoring.
- Debugging: Helps identify issues with DNS resolution, such as propagation delays or misconfigured DNS records.
The dig
command is an invaluable tool for anyone working with DNS. Whether you're a network administrator, a developer, or just someone who needs to understand how DNS works, dig
provides the necessary functionality to query DNS servers and interpret their responses. Regular use of dig
can aid in troubleshooting DNS issues and ensuring the reliability of domain name resolutions.
dig [options] [domain]
Perform DNS lookups.
Options:
-h, --help Show this help message.
-t, --type=TYPE Set the DNS record type.
-c, --class=CLASS Set the DNS record class.
-p, --port=PORT Set the DNS port number.
-q, --query=QUERY Set the DNS query.
-x, --xfr Perform a zone transfer.
-v, --verbose Increase verbosity.
-w, --width=WIDTH Set the output width.
Examples:
dig @8.8.8.8 google.com
dig -t A google.com
dig -x google.com
-h, --help: This option shows this help message.
-t, --type=TYPE: This option sets the DNS record type. The possible values for TYPE are:
A: A host address.
AAAA: A host address for IPv6.
CNAME: A canonical name.
MX: Mail exchanger.
NS: Name server.
PTR: Pointer.
SOA: Start of authority.
-c, --class=CLASS: This option sets the DNS record class. The possible values for CLASS are:
IN: Internet.
CH: Chaos.
HS: Hesiod.
-p, --port=PORT: This option sets the DNS port number. The default port number is 53.
-q, --query=QUERY: This option sets the DNS query. The query can be a domain name or a specific DNS record type.
-x, --xfr: This option performs a zone transfer. A zone transfer is a request for all of the DNS records for a zone.
-v, --verbose: This option increases verbosity. The more verbose the output, the more detailed it will be.
-w, --width=WIDTH: This option sets the output width. The width is the maximum number of characters per line.