Home/Engineer/Networking / Servers/Complete DNS Record Guide — …
Networking / ServersBeginnerUbuntuDebianCentOSmacOSDNSdig

Complete DNS Record Guide — Configuring A, CNAME, MX, TXT and Using dig

A practical rundown of each DNS record type, how to configure them, and how to diagnose DNS issues yourself with the dig command.

Contents
  1. DNS Record Types
  2. Example Record Configurations
  3. Querying DNS with dig
  4. DNS Troubleshooting Patterns
  5. TTL Strategy

DNS Record Types

TypePurposeExample
ADomain → IPv4example.com → 1.2.3.4
AAAADomain → IPv6example.com → 2001:db8::1
CNAMEDomain → domainwww → example.com
MXMail server@ → mail.example.com (priority 10)
TXTText (SPF, DKIM, etc.)"v=spf1 include:sendgrid.net ~all"
NSName server@ → ns1.cloudflare.com
CAACAs allowed to issue certificates@ → 0 issue "letsencrypt.org"

Example Record Configurations

CODE
; A record
example.com.     300  IN  A     1.2.3.4
www.example.com. 300  IN  A     1.2.3.4

; CNAME
www.example.com. 300  IN  CNAME example.com.

; MX (when using Gmail)
example.com. 300 IN MX 1  aspmx.l.google.com.
example.com. 300 IN MX 5  alt1.aspmx.l.google.com.

; SPF (anti-spam)
example.com. 300 IN TXT "v=spf1 include:_spf.google.com ~all"

; DMARC
_dmarc.example.com. 300 IN TXT "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.com"

Querying DNS with dig

Bash
# Query A record
dig example.com A

# Short output
dig example.com +short

# Query a specific DNS server (bypass cache)
dig @8.8.8.8 example.com A

# MX record
dig example.com MX

# TXT record (check SPF/DKIM)
dig example.com TXT

# Query NS
dig example.com NS

# Trace the full DNS resolution path
dig +trace example.com

DNS Troubleshooting Patterns

Bash
# 1. Confirm the domain points to the correct IP
dig +short example.com A

# 2. Query a specific name server directly before propagation
dig @ns1.your-registrar.com example.com A

# 3. Reverse DNS lookup (IP → domain)
dig -x 1.2.3.4

# 4. Check cache TTL via the SOA record
dig example.com SOA

# 5. DNSSEC validation
dig example.com +dnssec

TTL Strategy

  • Before a change: Lower TTL to 300 seconds (5 minutes). You can roll back quickly if something goes wrong.
  • After things stabilize: Raise TTL to 3600–86400 seconds to speed up DNS responses.
  • When using a CDN: Cloudflare proxied records have TTL managed automatically.
#DNS#dig
Editorial note

AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us

Questions & answers

Ask a question about this guide. We'll review and reply.