Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 36 ยท DNS and Proxying

DNS in Cloudflare: Authoritative DNS, TTLs and Managing Records

How Cloudflare authoritative DNS works: zones, nameservers, resolvers versus authoritative servers, TTLs, the DNS dashboard, bulk import and the DNS API.

DNS translates names such as www.example.com into addresses. Cloudflare is one of the largest DNS providers and also the heart of every other feature in this course: proxying, caching and security all begin as a DNS answer. This lesson explains the moving parts and then shows how to manage records in the dashboard, in bulk and through the API.

Resolvers and authoritative servers

Two kinds of server take part in every lookup.

  • A recursive resolver works for the visitor. It is run by the visitor's ISP or a public service (Cloudflare's own 1.1.1.1 is a recursive resolver). It asks questions and caches answers.
  • An authoritative nameserver holds the official records for a zone and answers for them. When you use Cloudflare as your DNS provider, Cloudflare's nameservers are authoritative for your domain.

Do not confuse the two products: 1.1.1.1 helps visitors look up any site; Cloudflare authoritative DNS answers for your domain.

sequenceDiagram
  participant B as Browser
  participant R as Recursive resolver
  participant Root as Root and .com servers
  participant CF as Cloudflare nameserver
  B->>R: www.example.com?
  R->>Root: who is authoritative for example.com?
  Root-->>R: ada.ns.cloudflare.com, bob.ns.cloudflare.com
  R->>CF: www.example.com?
  CF-->>R: 104.21.x.x (TTL 300)
  R-->>B: 104.21.x.x

The resolver caches the final answer for the TTL, so the next visitor skips these steps.

Zones and records

All of your records live in the zone for the domain. Each record has:

Field Meaning
Type A, AAAA, CNAME, MX, TXT and more (next lesson)
Name Hostname relative to the zone; @ means the root (apex), www means www.example.com
Content The value: an IP address, another hostname, text
TTL How long resolvers may cache the answer, in seconds, or Auto
Proxy status Proxied or DNS only (applies to A, AAAA and CNAME)

In the dashboard open DNS > Records. Use Add record, fill the fields and save. Changes are published to Cloudflare's whole network within seconds, much faster than most DNS hosts.

TTL explained

The time to live tells caches how long an answer may be reused. A long TTL reduces lookups and survives short outages of the nameserver; a short TTL lets changes take effect quickly.

  • Grey-cloud (DNS only) records let you pick a TTL, from 1 minute up to a day, or Auto (which is 300 seconds).
  • Proxied records always show Auto: the addresses returned are Cloudflare's, and you change origin IPs in the dashboard instantly without waiting on caches.

Before a planned migration, lower a record's TTL a day ahead so the real switch is quick; raise it again afterwards.

JS Stand-in: resolver cache with TTL

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The run shows the classic surprise: right after you edit a record, some visitors still see the old value until their cached copy expires. That is propagation delay, and it is purely a cache effect.

Managing records in bulk

Typing records one by one is slow for big zones. Cloudflare can import and export a zone file in BIND format (DNS > Records > Import and Export). A fragment looks like this:

TEXT
$ORIGIN example.com.
@      3600 IN A     203.0.113.10
www    3600 IN CNAME example.com.
@      3600 IN MX    10 mail.example.com.
@      3600 IN TXT   "v=spf1 include:_spf.example.net ~all"

Exporting is a good backup before large changes: store the file in Git. Importing never deletes existing records, so you can merge a file safely; Cloudflare reports which lines it could not understand.

JS Stand-in: parse a zone file

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Managing records through the API

Every dashboard action has an API equivalent. List records, then create one:

Terminal
# List all A records
curl -s "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records?type=A" \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

# Create a proxied A record
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records" \
  -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{"type":"A","name":"app","content":"203.0.113.20","ttl":1,"proxied":true}'

Updating is PATCH or PUT on /dns_records/{id}, and deleting is DELETE on the same path. Create a token limited to Zone: DNS: Edit for one zone and use it from scripts, for instance a nightly job that updates a record when your home IP changes (dynamic DNS).

Handy DNS features

  • Comments and tags on records document why a record exists; future you will be grateful.
  • Wildcard records such as *.example.com answer for any subdomain without its own record. Wildcards can be proxied on all plans, though some features need a specific hostname.
  • Multiple records for one name (for example several A records) give simple round-robin load distribution at the DNS level.
  • Secondary DNS and multi-provider setups let Cloudflare act as a secondary to another primary, an Enterprise feature for redundancy.
  • DNS analytics show query counts by type and response code, useful to spot misconfigurations or floods.

Common mistakes

  • Pointing the wrong nameservers at the registrar (each account gets its own pair).
  • Leaving old records after migrating an app, which leaks internal hostnames.
  • Forgetting that a CNAME cannot coexist with other records at the same name.
  • Expecting an instant worldwide change on a grey-cloud record with a long TTL.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is Cloudflare's role when your domain uses Cloudflare DNS?

    Your zone's records are answered by Cloudflare's authoritative nameservers. The 1.1.1.1 service is a separate recursive resolver.
  2. 2. What does the name @ stand for in a zone?

    @ is shorthand for the zone's own name, such as example.com.
  3. 3. Why might some visitors see the old IP right after you edit a grey-cloud record?

    Caches obey the TTL. Lower it before planned changes.
  4. 4. Which API token permission fits a script that only edits DNS for one domain?

    Least privilege: give it DNS edit rights on that single zone.

Summary

  • Resolvers ask on behalf of visitors; Cloudflare's nameservers are authoritative for your zone.
  • A record has type, name, content, TTL and (for web records) proxy status; @ is the apex.
  • TTLs control caching; lower them before migrations. Proxied records use Auto.
  • Import and export BIND files for backups and bulk work; the API covers everything the dashboard does.

Next: DNS record types and validation