dig is a command-line DNS diagnostic tool from BIND. It retrieves and displays various DNS properties of a hostname or IP address, such as its DNS records and authoritative name servers.
You can install
dig on most operating systems by downloading the latest version of BIND 9 from BIND’s website, or from the command line using a package manager. Click your operating system’s tab below to view instructions on how to install
Below are some common
dig commands to retrieve DNS information about a hostname. You can run any of the following examples in a terminal to see the output:
||Returns the A records found at a hostname.|
||Returns all records for a hostname, including NS and SOA records.|
||Queries a hostname’s name server directly instead of your ISP’s resolver. Include the record type parameter to retrieve records of a specific type at a hostname. DigitalOcean’s name server addresses are: ns1.digitalocean.com, ns2.digitalocean.com, and ns3.digitalocean.com|
||Only returns the records of a specified type at a hostname.|
||Only returns the IP addresses for all A records at a hostname.|
dig commands return one or multiple sections of information about the hostname’s DNS records depending on the syntax of your query. In the example below,
dig returned results for the query
; <<>> DiG 9.10.6 <<>> example.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50169 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 2, ADDITIONAL: 5 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ;example.com. IN A ;; ANSWER SECTION: example.com. 6108 IN A 188.8.131.52 ;; AUTHORITY SECTION: example.com. 52437 IN NS b.iana-servers.net. example.com. 52437 IN NS a.iana-servers.net. ;; ADDITIONAL SECTION: a.iana-servers.net. 195 IN A 184.108.40.206 a.iana-servers.net. 195 IN AAAA 2001:500:8f::53 b.iana-servers.net. 195 IN A 220.127.116.11 b.iana-servers.net. 195 IN AAAA 2001:500:8d::53
The most relevant sections for users tend to be the following:
Question Section: A reaffirmation of the query made to the DNS. In the example above,
dig queried the hostname
example.com and requested information about the hostname’s A records.
Answer Section: The records returned by the query. The answer section usually contains the most relevant information for
dig users. In the example above,
dig returned the A record for the IP address 18.104.22.168.
Authority Section: The authoritative name servers that host the hostname’s records. This can be helpful in verifying a hostname’s current delegation. For more information about how to delegate your hostname to point at DigitalOcean’s name servers, see our community tutorial.
Additional Section: Any extra information the resolver may have passed along with the answer. In the example above, the resolver passed along the IP addresses for example.com’s name servers in addition to the answer of the original query.