dig - Linux


The dig (Domain Information Groper) command in Linux is a powerful tool used for querying DNS (Domain Name System) servers. It is used for fetching DNS information, troubleshooting DNS-related issues, and ensuring correct DNS record setup. dig is highly useful for network administrators and developers who need to diagnose DNS problems or simply retrieve information about domain names.


The basic syntax for the dig command is:

dig [@server] [domain] [query-type] [options]
  • @server: Specify the DNS server to query. If omitted, dig uses the system’s default DNS server.
  • domain: The domain name you are querying about.
  • query-type: Type of DNS record to retrieve (e.g., A, MX, TXT). If omitted, dig defaults to querying for the A record.
  • options: Additional options to customize or refine the query.


  • +short: Provides a concise response by displaying just the answer to the query.
  • -x: Reverse lookup mode. Instead of a name, provide an IP address to find its associated hostname.
  • +trace: Traces the path of the query across DNS servers to reach its authoritative source.
  • +nocmd: Skips printing the query itself in the output, showing only the result.
  • +nocomments: Removes comments from the output.
  • +nostats: Suppresses statistics from the output.
  • +noquestion: Does not display the question section in the output.
  • +noadditional: Omits the additional section from the output.
  • +noauthority: Excludes the authority section from the output.
  • +tcp: Forces dig to use TCP instead of UDP for the query.


  1. Basic DNS Query:
    dig example.com
  2. Query Specific Record Type (e.g., MX):
    dig example.com MX +short
  3. Reverse DNS Lookup:
    dig -x +noall +answer
  4. Trace Route of DNS Resolution:
    dig +trace example.com

Common Issues

  • Timeouts or No Response: Make sure the DNS server you are querying is up and accessible. Check network settings or try querying another server.
  • Non-Responsive for Certain Record Types: Some DNS servers restrict information or record types. Try a different server or verify DNS settings.
  • Incorrect Results: Check for typos in the domain or record type. Clear local DNS cache or wait for DNS propagation if records are recently changed.


dig can be combined with other commands for more complex tasks:

  • Saving Output to a File:
    dig example.com > dns_results.txt
  • Using in Scripts to Monitor DNS changes:
    if dig example.com | grep 'Expected IP'; then
        echo "No DNS changes detected."
        echo "DNS change detected!"
  • nslookup: Another tool for querying DNS servers, generally simpler than dig.
  • host: Similar to dig but with fewer options, suitable for basic queries.

For further reading and more detailed information, consult the dig man page (man dig) or visit the ISC documentation.