1. Home
  2. Blog
  3. DevOps

DevOps

DNS Records Explained: A, AAAA, CNAME, MX, TXT and TTL With Real Lookups

DNS turns names like example.com into the addresses computers use. When a website moves, email stops arriving or a domain verification fails, the answer is usually in a DNS record. We ran real lookups to show what each record type looks like and how to change them safely.

11 min read
DNS records explained: A, AAAA, CNAME, MX, TXT and TTL with real lookups

Key takeaways

  • DNS records map names to addresses and services: A/AAAA for IPs, CNAME for aliases, MX for mail, TXT for text such as SPF.
  • A CNAME cannot sit at the root domain or alongside other records with the same name.
  • TTL controls how long answers are cached. In our test, a repeat lookup took 7 ms instead of 39 ms.
  • Lower the TTL a day before a planned change, so mistakes and moves take effect quickly.

A company moves its website to a new host, updates DNS, and half its visitors still see the old site the next day. Another adds a new email service and suddenly its invoices land in spam. Both stories come down to DNS records: what they contain, how long they are cached, and the rules each type must follow.

We looked up public test domains from a Windows machine using Python’s resolver and the nslookup tool. The results are from that run; IP addresses are summarised rather than listed, since they can change. Provider dashboards and command options vary, so some steps below are general guidance.

What is DNS?

The Domain Name System is the internet’s distributed directory. Computers connect using IP addresses, but people remember names. DNS answers the question “what is the address, or mail server, or verification text, for this name?” It is distributed: no single server knows everything, and each domain’s owner controls the records for their own names through their DNS hosting provider.

How a lookup works

  1. Your app asks the operating system to resolve example.com.
  2. The OS asks a recursive resolver, usually run by your network, ISP or a public DNS service.
  3. If the resolver has no cached answer, it asks the root servers, then the .com servers, then the domain’s authoritative name servers.
  4. The answer comes back with a TTL, and is cached along the way.
example.com:            3 address(es), v4=2, v6=1, 0.039s
repeat lookup:          0.007s
does-not-exist.invalid: gaierror 11001

The first lookup took 39 ms; the repeat took 7 ms because the answer was already cached. The .invalid name, reserved so that it never exists, failed with a “host not found” error, which is what an application sees when a domain is mistyped or has expired.

Record types at a glance

Type Points to Typical use
A IPv4 address Website and server addresses
AAAA IPv6 address The same, for IPv6
CNAME Another name Aliases, such as www or a SaaS custom domain
MX Mail server name and priority Receiving email
TXT Free text SPF, DKIM, DMARC, domain verification
NS Name servers Which servers are authoritative for the domain
CAA Certificate authorities Who may issue TLS certificates
SRV Host and port for a service Some VoIP, chat and directory services

A and AAAA records

An A record maps a name to an IPv4 address, such as 203.0.113.10; an AAAA record maps it to an IPv6 address. A name can have several of each, and our lookup of example.com returned two IPv4 addresses and one IPv6 address. Clients usually pick among multiple addresses, which spreads load and provides some redundancy, though it is not a replacement for a proper load balancer or health checks.

CNAME records

www.example.com.    CNAME   example.com.
shop.example.com.   CNAME   stores.some-saas.example.

A CNAME says “this name is an alias; look up that other name instead.” It is ideal for pointing a subdomain at a service whose IP addresses may change, since the provider manages the target’s records. Two rules cause most CNAME problems:

  • A name with a CNAME cannot have any other records, such as MX or TXT, at the same name.
  • Therefore the bare root domain (example.com itself), which must have NS and SOA records, cannot be a CNAME.

Many DNS providers offer “ALIAS”, “ANAME” or “CNAME flattening” to point the root domain at another name; the provider resolves it behind the scenes and returns A records.

MX records

nslookup -type=MX example.com
example.com   MX preference = 0, mail exchanger = (root)

MX records name the servers that receive email for a domain, each with a preference number; lower numbers are tried first, and higher ones are backups. Our lookup shows a special case: example.com publishes a null MX, a single MX pointing to the root, “.”. It is a standard way of saying “this domain accepts no email”, so senders give up immediately instead of retrying. MX targets must be host names with A or AAAA records, not IP addresses and not CNAMEs.

TXT records

nslookup -type=TXT example.com
example.com   text = "v=spf1 -all"

TXT records hold text that other systems read. The most important uses are email authentication:

  • SPF lists which servers may send mail for the domain. v=spf1 -all, which we found on example.com, means “no server may send mail for this domain”, the companion to its null MX.
  • DKIM publishes public keys used to verify signatures on outgoing mail.
  • DMARC tells receivers what to do when SPF or DKIM checks fail, and where to send reports.

TXT records are also used to prove domain ownership to services such as search consoles, email providers and certificate authorities. Delete old verification records only when you are sure nothing still relies on them.

Tip: A domain should have exactly one SPF record. Adding a second v=spf1 TXT record for a new email service, instead of merging it into the existing one, makes SPF fail for everyone, a common cause of mail suddenly landing in spam.

NS and SOA records

NS records list the authoritative name servers for a domain, usually set at the registrar. If they point to the wrong provider, every other record you edit is ignored, because the world is asking a different set of servers. The SOA (start of authority) record holds administrative details for the zone, such as the primary server and timers. You rarely edit it directly.

Other useful records

CAA records restrict which certificate authorities may issue TLS certificates for your domain, reducing the risk of a mis-issued certificate. PTR records provide reverse lookups from IP to name, which mail servers check for sending IPs. SRV records point clients to the host and port of specific services. Most websites only need A/AAAA, CNAME, MX and TXT, but knowing the others helps when a service’s setup guide asks for them.

TTL and caching

Every record has a TTL, time to live, in seconds. Resolvers and devices cache the answer for that long. A TTL of 3600 means a change may take up to an hour to be seen everywhere; 86400 means up to a day. Our repeat lookup, 7 ms against 39 ms, shows why caching exists: it makes the internet faster and reduces load on DNS servers. The cost is that changes are not instant, which is why people talk about “DNS propagation”. There is no real propagation step; caches simply expire at different times.

Changing DNS safely

  1. Lower the TTL on the records you will change, for example to 300 seconds, at least one old TTL period beforehand.
  2. Prepare the new destination and test it directly, for example with a hosts file entry, before switching.
  3. Make the change and verify it by querying the authoritative name servers directly.
  4. Keep the old server running until the old TTL has expired everywhere.
  5. Raise the TTL again once everything is stable.

Export or screenshot your current records before any change. A single deleted TXT record can break email authentication or a verification that no one remembers setting up. If your infrastructure is managed as code, as in our Terraform tutorial, DNS records can be reviewed and versioned like everything else.

Troubleshooting

  • Check what the world sees: nslookup name on Windows, or dig name on Linux and macOS.
  • Ask a specific resolver to compare answers, such as a public DNS service.
  • Check the NS records first if your changes seem to be ignored.
  • Separate DNS from the web server: if the name resolves correctly but the page fails, the problem is further along; the status code tells you where, as listed in our HTTP status codes cheat sheet.
  • Flush local caches, such as ipconfig /flushdns on Windows, when testing a change.
  • Remember HTTP caching too: a correct DNS answer can still show an old page cached by a browser or CDN, as covered in HTTP caching explained.

Final thoughts

DNS records are simple individually: A and AAAA for addresses, CNAME for aliases, MX and TXT for email and verification. Most problems come from the rules around them, such as no CNAME at the root, one SPF record per domain and caching controlled by TTL. Lower TTLs before changes, keep a copy of your records, and check what authoritative servers actually return before declaring a change done.

Frequently asked questions

What is the difference between an A record and a CNAME?

An A record maps a name directly to an IPv4 address. A CNAME maps a name to another name, which is then resolved to an address.

Can I use a CNAME on my root domain?

Not with a standard CNAME, because the root must also have NS and SOA records. Many providers offer ALIAS, ANAME or CNAME flattening instead.

What does TTL mean in DNS?

Time to live: how many seconds resolvers may cache a record. Lower values make changes visible sooner; higher values reduce lookups.

What is a TXT record used for?

Mainly email authentication (SPF, DKIM, DMARC) and proving domain ownership to services such as email providers and search consoles.

Why is my DNS change not showing yet?

Resolvers are still serving cached answers until the old TTL expires, or the domain’s NS records point to a different provider than the one you edited.

Keep learning

Work with Stack Quora

Need help with testing, WordPress or SEO?

We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.

Keep reading

More guides on testing, AI & modern development

Enjoyed this article? Pick a topic and jump straight into our newest tutorials.

Artificial Intelligence

Prompt Injection Explained: How AI Apps Get Tricked and How to Defend Them

Prompt injection explained for builders: direct and indirect attacks, why keyword filters fail (our test blocked 1 of 4), and…

Read article →
DevOps

DNS Records Explained: A, AAAA, CNAME, MX, TXT and TTL With Real Lookups

DNS records explained with lookups we ran: how resolution works, A and AAAA, CNAME rules, MX and null MX, TXT…

Read article →
DevOps

Feature Flags Explained: Safe Releases, Gradual Rollouts and Flag Hygiene

Feature flags explained with a rollout simulation we ran: flag types, percentage rollouts with stable hashing, kill switches, allow lists,…

Read article →
Test Automation

Test Data Generation With Python Faker: Realistic, Repeatable and Safe Data

Test data generation with Python Faker, run and measured: seeding for repeatable data, locales, unique values, domain-shaped records, edge cases…

Read article →
Software Testing

Shift-Left Testing Explained: Find Bugs Earlier Without Slowing the Team

Shift-left testing explained: what it means, why early defects are cheaper, practices from requirement reviews to CI checks, the tester's…

Read article →
Databases & SQL

SQL String Functions Explained: TRIM, SUBSTR, REPLACE, CONCAT and Data Cleanup

SQL string functions explained with queries we ran: concatenation and NULL, TRIM, UPPER and LOWER, SUBSTR and INSTR, REPLACE, padding,…

Read article →
Databases & SQL

SQL Triggers Explained: BEFORE and AFTER Triggers, Audit Logs and Pitfalls

SQL triggers explained with triggers we ran: BEFORE vs AFTER, OLD and NEW, audit logs, validation, stock updates, WHEN conditions,…

Read article →
Software Development

Python JSON Module Explained: dumps, loads, Custom Types and Common Errors

The Python JSON module explained with code we ran: dumps and loads, files, type conversions, dates and decimals, custom encoders,…

Read article →
Software Development

ES Modules vs CommonJS: How JavaScript Imports Work in Node.js, Tested

ES modules vs CommonJS explained with code we ran in Node.js: import and export syntax, require, live bindings, caching, top-level…

Read article →
Software Development

Python Regex Explained: Patterns, Groups, Lookaheads and Pitfalls, Tested

Python regex explained with patterns we ran: search vs match, findall, groups and named groups, greedy vs lazy, sub, lookaheads,…

Read article →
Artificial Intelligence

LLM Structured Output Explained: Getting Reliable JSON From AI Models

LLM structured output explained with validation we ran in Pydantic: JSON mode and schemas, constrained decoding, the ways model output…

Read article →
DevOps

SSH Keys Explained: How They Work, ssh-keygen, Ed25519 and Safe Habits

SSH keys explained with keys we generated: public vs private keys, ssh-keygen, Ed25519 vs RSA, fingerprints, passphrases, ssh-agent, authorized_keys, config…

Read article →
DevOps

HTTP Caching Explained: Cache-Control, ETag and 304 Responses, With a Live Test

HTTP caching explained with a small server we ran: Cache-Control directives, max-age, no-cache vs no-store, ETag revalidation and 304 responses,…

Read article →
Test Automation

API Contract Testing Explained: Catch Breaking Changes Before They Ship

API contract testing explained with a schema check we ran: what a contract is, consumer-driven contracts, Pact, OpenAPI, which changes…

Read article →
Software Testing

Risk-Based Testing Explained: Score Risks, Build a Matrix and Test What Matters

Risk-based testing explained step by step: identifying risks, scoring likelihood and impact, building a risk matrix, mapping risk to test…

Read article →
Databases & SQL

SQL Constraints Explained: NOT NULL, UNIQUE, CHECK and FOREIGN KEY, Tested

SQL constraints explained with tests we ran: NOT NULL, UNIQUE, CHECK, DEFAULT, PRIMARY and FOREIGN KEY, the NULL loopholes, SQLite's…

Read article →
Databases & SQL

SQL Date Functions Explained: Adding, Comparing and Grouping Dates Without Bugs

SQL date functions explained with queries we ran: adding intervals, month-end surprises, date differences, the BETWEEN trap, grouping by day,…

Read article →
Software Development

Python asyncio Explained: async, await, gather and TaskGroup With Real Timings

Python asyncio explained with code we timed: coroutines, await, gather, TaskGroup, error handling, timeouts, limiting concurrency and the blocking-call mistake…

Read article →
Software Development

Debounce vs Throttle in JavaScript: How They Work, When to Use Each, Tested

Debounce vs throttle in JavaScript explained with timings we measured in Node.js: how each works, simple implementations, leading and trailing…

Read article →
Software Development

Python Context Managers Explained: The with Statement, contextlib and Real Uses

Python context managers explained with code we ran: how with works, __enter__ and __exit__, contextlib.contextmanager, suppress, ExitStack, database transactions and…

Read article →
Artificial Intelligence

LLM Temperature and Top-p Explained: How AI Models Choose Their Next Word

LLM temperature and top-p explained with a simulation we ran: how probabilities are reshaped, what top-p keeps, recommended settings by…

Read article →
DevOps

YAML Explained: Syntax, the Norway Problem and Other Traps We Tested

YAML explained with a parser test: basic syntax, lists and maps, the Norway problem, versions turning into floats, octal zip…

Read article →
DevOps

Cron Jobs Explained: Syntax, Real Schedules and the Mistakes That Break Them

Cron jobs explained with schedules we verified: the five fields, operators, real examples, the day-of-month OR day-of-week trap, environment problems,…

Read article →
Software Testing

Bug Life Cycle in Software Testing: Every Status, Who Owns It and Common Mistakes

The bug life cycle explained: every defect status from New to Closed, who owns each step, rejected, deferred and reopened…

Read article →
Test Automation

Property-Based Testing in Python: Hypothesis Finds the Bugs Your Examples Miss

Property-based testing explained with Hypothesis tests we ran: properties vs examples, strategies, shrinking, the real bugs it found in our…

Read article →
Databases & SQL

SQL Pagination Explained: OFFSET vs Keyset, With a Million-Row Test

SQL pagination explained with a million-row test we ran: LIMIT and OFFSET, why deep pages get slow, keyset (cursor) pagination,…

Read article →
Databases & SQL

SQL EXISTS vs IN: Differences, the NOT IN NULL Trap and Performance

SQL EXISTS vs IN explained with queries we ran: how each works, why NOT IN returns no rows when a…

Read article →
Artificial Intelligence

LLM Tokens Explained: How AI Models Read Text, Count Costs and Fill Context Windows

LLM tokens explained with a tokenizer we ran: how text is split, why counts differ by language and tokenizer, context…

Read article →
Software Testing

The Test Pyramid Explained: Layers, Ratios and When to Break the Shape

The test pyramid explained: unit, integration and end-to-end layers, sensible ratios, the ice cream cone anti-pattern, the testing trophy and…

Read article →
Test Automation

pytest Fixtures Explained: Scope, yield Teardown, conftest.py and Factories

pytest fixtures explained with a suite we ran: how fixtures work, scopes, yield teardown, conftest.py, factory fixtures, parametrized fixtures, built-ins…

Read article →
Artificial Intelligence

AI Hallucinations Explained: Why Language Models Make Things Up and How to Reduce It

AI hallucinations explained: what they are, why language models produce them, common types, how to reduce them with grounding and…

Read article →
Test Automation

Mocking in Python: unittest.mock, patch and the Mistakes That Make Tests Lie

Mocking in Python with unittest.mock, tested: Mock and return_value, side_effect, patching where a name is used, spec and autospec, mocking…

Read article →
Software Testing

Code Coverage Explained: Line vs Branch Coverage and What 100% Really Means

Code coverage explained with a real coverage.py run: line, branch and condition coverage, reading a report, why 100% coverage can…

Read article →
Artificial Intelligence

What Are AI Agents? How They Work, With a Simple Agent Loop You Can Run

What are AI agents? A plain guide to the agent loop, tools, memory and guardrails, with a small Python loop…

Read article →
Test Automation

TDD vs BDD: Key Differences, One Feature Built Both Ways and When to Use Each

TDD vs BDD explained with one discount feature built both ways: red-green-refactor with code we ran, Given-When-Then scenarios, tools, trade-offs…

Read article →
Software Testing

User Acceptance Testing (UAT): Process, Checklist and Real Examples

User acceptance testing explained: who runs it, how it differs from QA, a seven-step process, a UAT test case template,…

Read article →