# dig Command Reference ## What it does Advanced DNS lookup tool with more detailed output and flexibility than nslookup. Preferred by network professionals. ## Basic Usage ```bash dig google.com # Basic A record lookup dig @8.8.8.8 google.com # Use specific DNS server dig google.com +short # Show only the answer ``` ## Record Type Queries | Record Type | Command | Description | |-------------|---------|-------------| | `A` | `dig google.com A` | IPv4 address (default) | | `AAAA` | `dig google.com AAAA` | IPv6 address | | `MX` | `dig google.com MX` | Mail exchange records | | `NS` | `dig google.com NS` | Name servers | | `TXT` | `dig google.com TXT` | Text records | | `CNAME` | `dig www.github.com CNAME` | Canonical name | | `SOA` | `dig google.com SOA` | Start of authority | ## Output Control ```bash # Short answer only dig google.com +short # No additional info dig google.com +noall +answer # Trace full DNS path dig google.com +trace # Reverse DNS lookup dig -x 8.8.8.8 ``` ## Advanced Options | Argument | Description | |----------|-------------| | `+short` | Show only the answer | | `+trace` | Trace delegation path | | `+noall +answer` | Show only answer section | | `+tcp` | Use TCP instead of UDP | | `+time=N` | Set query timeout | | `-x IP` | Reverse DNS lookup | ## Quick Commands ```bash # Clean output (just IP) dig google.com +short # Mail servers dig gmail.com MX +short # All DNS records dig google.com ANY # Reverse lookup dig -x 142.250.191.46 +short # Trace DNS resolution dig google.com +trace ``` ## Query Specific Servers ```bash # Google DNS dig @8.8.8.8 google.com # Cloudflare DNS dig @1.1.1.1 google.com # Compare multiple servers dig @8.8.8.8 @1.1.1.1 google.com ``` ## Reading Results ```bash ;; QUESTION SECTION: ;google.com. IN A ;; ANSWER SECTION: google.com. 300 IN A 142.250.191.46 ``` - `QUESTION` → What was asked - `ANSWER` → The response - `300` → TTL (time to live) in seconds - `IN` → Internet class - `A` → Record type ## Pro Tips > - Use `+short` for scripts and automation > - `+trace` shows the full DNS resolution path > - More reliable and detailed than nslookup > - Perfect for DNS troubleshooting