The DNS Detective
Published: 2026-03-03
URL: https://thecodinggopher.substack.com/p/dig-command-in-linux
If grep is a librarian and wget is a courier, dig is the phone book operator. When you type google.com into your browser, your computer doesn’t actually know where that is. It needs an IP address (like 142.251.41.46) to connect.
The system that translates names to numbers is called DNS (Domain Name System). dig allows you to manually ask the questions your browser asks automatically. It is the primary tool network engineers use to debug connection issues, verify website migrations, or check email settings.
What is Dig? dig stands for Domain Information Groper. (Yes, really). It queries DNS nameservers for information about host addresses, mail exchanges, and related information. If a website is “down,” dig tells you if the problem is with the website itself or just the map leading to it. dig (Domain Information Groper) is the modern, flexible tool preferred by administrators.
It shows the raw data exactly as the DNS server sends it. nslookup (Name Server Lookup) is an older, legacy tool (especially on Linux/Unix). It processes and formats the response, sometimes hiding details or errors.
The Basic Syntax The simplest command is just the tool followed by the domain: dig google.comDon’t panic. The output of dig is famous for being verbose. It prints a lot of technical header info. You usually only care about one specific part: The Answer Section.
The Output Decoded: ;; QUESTION SECTION: ;google.com. IN A ;; ANSWER SECTION: google.com. 222 IN A 142.250.191.206Question: You asked “Where is google.com?” (specifically, its ‘A’ record).
An A record (Address record) is the most fundamental type of DNS record that maps a domain name (e.g., example.com) directly to a physical IPv4 address (e.g., 192.0.2.1). It acts as a directory for the internet, directing traffic to the correct server hosting a website or service. Answer: The internet replied, “It is at 142.250.191.206”.
A records (Address) directly map a domain or subdomain to an IPv4 address, essential for directing traffic to a specific server. CNAME records (Canonical Name) map an alias name to another domain name rather than an IP, commonly used for subdomains (e.g., www) pointing to a root domain. Use A records for direct IP targeting, and CNAMEs for flexibility with dynamic IP changes.
The ANSWER, AUTHORITY, and ADDITIONAL sections provide detailed information about a DNS query, broken down by their role in DNS resolution. ANSWER SECTION: Contains the actual DNS records you requested (e.g., the IP address of a domain). AUTHORITY SECTION: Lists the authoritative name servers that are responsible for the domain and hold the definitive zone records. ADDITIONAL SECTION: Provides extra information to improve efficiency, such as the IP addresses (glue records) for the name servers listed in the Authority section.
Essential Features and Flags While the default output is detailed, you can customize dig to be surgical. +short (The “Just give me the IP” mode): This removes all the header noise and copyright info, leaving you with just the result. Perfect for quick checks or scripts. dig google.com +short
Output: 142.250.191.206Looking up Specific Records (MX, TXT, NS):
By default, dig looks for the A record (the IP address). But you often need other info: MX (Mail Exchange): Where are emails for this domain sent? Running dig gmail.com MX +short queries the DNS for Gmail's mail exchange records, returning priority numbers and mail server hostnames, typically starting with 5 gmail-smtp-in.l.google.com. and several alt servers.
These servers manage incoming mail for the domain, with lower priority numbers indicating higher preference. dig gmail.com MX +short TXT (Text): Often used for verification tokens (like for Google Search Console). TXT (text) is a DNS record type used to store arbitrary, human- or machine-readable text information about a domain, such as verification codes, SPF, or DKIM records. dig example.com TXTNS (Name Server): Who is the “manager” of this domain?
It is a type of DNS query that identifies the authoritative name servers responsible for a domain, which hold the official DNS records (e.g., A, MX) for that domain. dig amazon.com NS @server (The Second Opinion): By default, dig asks your computer’s default DNS (usually your ISP).
But what if your ISP is lying or broken? You can force dig to ask a specific server, like Google’s public DNS (8.8.8.8). dig google.com @8.8.8.8This is the #1 way to troubleshoot “Is the internet broken, or is just my DNS broken?” The command dig @8.8.8.8 archlinux.org MX uses the Domain Information Groper (dig) tool to query Google's public DNS server (8.8.8.8) for the Mail Exchange (MX) records of archlinux.org.
It retrieves information on which servers are authorized to receive email for the domain, bypassing local DNS settings for troubleshooting. 𝐋𝐞𝐚𝐫𝐧 𝐭𝐨 𝐛𝐮𝐢𝐥𝐝 𝐆𝐢𝐭, 𝐃𝐨𝐜𝐤𝐞𝐫, 𝐑𝐞𝐝𝐢𝐬, 𝐇𝐓𝐓𝐏 𝐬𝐞𝐫𝐯𝐞𝐫𝐬, 𝐚𝐧𝐝 𝐜𝐨𝐦𝐩𝐢𝐥𝐞𝐫𝐬, 𝐟𝐫𝐨𝐦 𝐬𝐜𝐫𝐚𝐭𝐜𝐡. Get 40% OFF CodeCrafters: https://app.codecrafters.io/join?via=the-coding-gopher This Substack is reader-supported. To receive new posts and support my work, consider becoming a free or paid subscriber. +trace (The Detective Path): This is the “full audit.” It starts at the root of the internet and follows the chain of command down to the specific domain.
It shows you exactly how the resolution happens step-by-step. dig google.com +trace This section has five columns, each of which stands for: The domain name that is to be looked up. Time to live period – a setting that tells the DNS resolver how long to cache a query before requesting a new one. Class of the query – IN refers to the Internet. DNS query type – can be A, AAAA, CNAME, MX, NS, PTR, CERT, SRV, TXT, SOA, etc.
The IP address associated with the domain name. Summary Table Conclusion Dig removes the mystery from the internet’s phonebook. Instead of guessing why a site won’t load, dig lets you ask the network exactly what it sees.
It separates “the server is down” from “the address is wrong.” This Substack is reader-supported. To receive new posts and support my work, consider becoming a free or paid subscriber. Thanks for reading!
This post is public so feel free to share it. Share