Overview
dig directly queries DNS servers to look up various DNS records (A, AAAA, MX, NS, CNAME, TXT, etc.) for a specific domain. By default, it queries for 'A' records, but you can specify a particular record type.
Key Features
- Lookup various DNS record types (A, AAAA, MX, NS, CNAME, TXT, etc.)
- Query specific DNS servers
- Reverse DNS lookup (find domain name from IP address)
- Support for concise output formats
- Provide DNS query response times and detailed information
Key Options
The dig command allows for fine-grained control over query methods and output formats through various options.
Query Type and Target
Output Control
Generated command:
Try combining the commands.
Description:
`dig` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Various usage examples of the dig command.
Basic A Record Lookup
dig google.com
Looks up the IP address (A record) for google.com.
MX (Mail Exchanger) Record Lookup
dig google.com MX
Retrieves mail server information for google.com.
Lookup Using a Specific DNS Server
dig @8.8.8.8 naver.com
Uses Google Public DNS (8.8.8.8) to look up the A record for naver.com.
Reverse DNS Lookup
dig -x 8.8.8.8
Looks up the domain name corresponding to a specific IP address (e.g., 8.8.8.8).
Concise Output
dig google.com +short
Outputs the A record for google.com concisely.
Output Answer Section Only
dig google.com +noall +answer
Outputs only the answer section of the A record for google.com, removing unnecessary information.
Installation
dig is provided as part of the `dnsutils` (Debian/Ubuntu) or `bind-utils` (CentOS/RHEL) package on most Linux distributions. If it is not installed by default, you can install it using the following commands.
Debian/Ubuntu
sudo apt update && sudo apt install dnsutils
Installs using the apt package manager.
CentOS/RHEL/Fedora
sudo yum install bind-utils\n# or\nsudo dnf install bind-utils
Installs using the yum or dnf package manager.
Tips & Notes
Useful tips and points to note when using dig.
Commonly Used Record Types
Major DNS record types that can be looked up with dig.
- A: IPv4 Address
- AAAA: IPv6 Address
- MX: Mail Exchanger
- NS: Name Server
- CNAME: Canonical Name (Alias)
- TXT: Text Information (SPF, DKIM, etc.)
- PTR: Pointer Record (IP -> Domain)
Checking DNS Cache
dig queries DNS servers directly without using the local system's cache, making it useful for immediately verifying DNS changes. To check the local cache, you can use commands like `systemd-resolve --statistics` or `nscd -g` (if using the nscd service).
Troubleshooting Aid
When experiencing network-related issues such as website access problems or email sending failures, dig can be used to verify if the DNS settings are correct. Specifically, by querying with a specified DNS server, it helps determine whether the issue lies with the ISP's DNS server or the domain itself.