BeginnerLesson 5 of 128 min read

Domains, DNS and Connecting Your Own Address to a Builder

Understand how a domain name finds a website: read a DNS zone, follow CNAME chains, avoid the apex CNAME mistake, know why changes take time to spread, and check a small resolver written in two languages against each other.

In this lesson you will

  • Name the main DNS record types
  • Follow a CNAME chain to an address
  • Avoid common DNS mistakes
  • Estimate how long a change takes

About 28 minutes

pineandhoney.example, pointed at the builder

Priya’s builder gives her a free address such as pine-honey.builder-a.example, and she wants customers to type her own name, pineandhoney.example. (The names in this lesson use the reserved .example ending, which belongs to nobody.) A domain name is registered with a registrar for a yearly fee, and the Domain Name System, DNS, is the phone book that turns names into the addresses of computers. You manage it by adding records to the domain’s zone, in a screen at your registrar or your builder, and no-code tools usually give a short list of records to copy. A little understanding of the records prevents most of the mistakes that make a site disappear for a day.

The records that matter are few. An A record maps a name to an IPv4 address, and an AAAA record to an IPv6 address. A CNAME record says “this name is an alias of another name”, for instance www points to the builder’s host, and the resolver then looks up that name instead, which lets the builder change its addresses without bothering you. An MX record names the mail servers for the domain, with priorities, where the lower number is tried first. A TXT record holds text, used to prove that you own the domain and to publish email authentication rules. Every record has a TTL, time to live, in seconds, which tells resolvers how long they may keep the answer. After you change a record, old answers can live in caches until their TTL runs out, so changes take up to the old TTL to spread, which is why a site sometimes works for you and not for a friend. One rule catches many beginners: a name cannot have a CNAME and other records at the same time, and the bare domain, the apex, must have other records such as MX and NS, so a CNAME there is invalid.

Record Example Meaning
A @ A 203.0.113.10 Name to IPv4 address
CNAME www CNAME sites.builder-a.example. Alias to another name
MX @ MX 10 mail.provider.example. Mail server, lower number first
TXT @ TXT “v=spf1 include:mail.provider.example ~all” Text for verification and email rules
TTL 3600 Seconds a resolver may cache the answer
const zone = `@        3600 A     203.0.113.10
www      3600 CNAME sites.builder-a.example.
shop     300  CNAME shop.builder-b.example.
blog     3600 CNAME www
@        3600 MX 10 mail1.provider.example.
@        3600 MX 20 mail2.provider.example.
@        3600 TXT   "v=spf1 include:mail.provider.example ~all"
loop1    300  CNAME loop2
loop2    300  CNAME loop1
sites.builder-a.example.   600 A 198.51.100.7
shop.builder-b.example.    600 A 198.51.100.99`;
const ORIGIN = 'pineandhoney.example.';
const fq = n => n === '@' ? ORIGIN : n.endsWith('.') ? n : n + '.' + ORIGIN;
const recs = zone.trim().split('\n').map(l => l.trim().split(/\s+/)).map(p => ({ name: fq(p[0]), ttl: Number(p[1]), type: p[2], data: p[2] === 'MX' ? { pri: Number(p[3]), host: fq(p[4]) } : p[2] === 'CNAME' ? fq(p[3]) : p.slice(3).join(' ').replace(/^"|"$/g, '') }));
function resolve(name, depth = 0, minTtl = Infinity) {
  if (depth > 8) return { error: 'CNAME loop', chain: [] };
  const c = recs.find(r => r.name === name && r.type === 'CNAME');
  if (c) { const r = resolve(c.data, depth + 1, Math.min(minTtl, c.ttl)); return { ...r, chain: [name, ...(r.chain || [])] }; }
  const a = recs.find(r => r.name === name && r.type === 'A');
  return a ? { address: a.data, ttl: Math.min(minTtl, a.ttl), chain: [name] } : { error: 'NXDOMAIN', chain: [name] };
}
const names = ['pineandhoney.example.', 'www.pineandhoney.example.', 'shop.pineandhoney.example.', 'blog.pineandhoney.example.', 'loop1.pineandhoney.example.', 'missing.pineandhoney.example.'];
const out = {};
names.forEach(n => { const r = resolve(n); out[n] = r; console.log(n.padEnd(30), r.error ? r.error : r.address + '  (TTL ' + r.ttl + 's via ' + r.chain.length + ' name' + (r.chain.length > 1 ? 's' : '') + ')'); });
const mx = recs.filter(r => r.type === 'MX').sort((a, b) => a.data.pri - b.data.pri).map(r => r.data.pri + ' ' + r.data.host);
console.log('mail servers in order of preference:', mx.join(' | '));
const apexCname = recs.some(r => r.name === ORIGIN && r.type === 'CNAME');
console.log('CNAME at the apex (not allowed):', apexCname, '| the shortest TTL on the shop name is', out['shop.pineandhoney.example.'].ttl, 's, so a change can take about', Math.round(out['shop.pineandhoney.example.'].ttl / 60), 'minutes to spread');
console.log('DATA ' + JSON.stringify({ out, mx, apexCname }));
pineandhoney.example.          203.0.113.10  (TTL 3600s via 1 name)
www.pineandhoney.example.      198.51.100.7  (TTL 600s via 2 names)
shop.pineandhoney.example.     198.51.100.99  (TTL 300s via 2 names)
blog.pineandhoney.example.     198.51.100.7  (TTL 600s via 3 names)
loop1.pineandhoney.example.    CNAME loop
missing.pineandhoney.example.  NXDOMAIN
mail servers in order of preference: 10 mail1.provider.example. | 20 mail2.provider.example.
CNAME at the apex (not allowed): false | the shortest TTL on the shop name is 300 s, so a change can take about 5 minutes to spread

The program read a small zone file, a list of records with their names, lifetimes, types and data, and used it as a resolver would. The bare domain, the apex, resolves directly to its A record, 203.0.113.10. The name www is a CNAME to the builder’s host, so the resolver follows the alias to sites.builder-a.example and finds the builder’s address, 198.51.100.7, and the answer may be cached for the shortest lifetime along the chain, 600 seconds. The shop name is an alias to a second builder, with a short TTL of 300 seconds, which is a good habit when you expect to change a record soon. The blog name is an alias of www, and so a chain of two aliases leads to the same address.

Two names show the failures. The pair loop1 and loop2 point at each other, and the resolver gave up with “CNAME loop” after a few steps: real resolvers do the same, and the site would simply not load. A name that has no record at all gives NXDOMAIN, “no such domain”, which is also what a mistyped name in a record gives. The mail servers are listed in order of preference, 10 mail1.provider.example. first and 20 mail2.provider.example. as a fallback, since the lower number wins. The program also checks the apex rule: it found no CNAME at the apex (False), because a bare domain must carry MX, NS and other records which a CNAME forbids. Builders that ask you to point the bare domain at a name usually offer an ALIAS or ANAME record, or an A record with an address, and their instructions tell you which, so follow their instructions exactly.

Independent check: a second resolver was written in Python from the same zone text, with its own parser and its own way of following aliases, a loop with a list of visited names, and it gives the same address, the same lifetime and the same chain length for all six names, and the same classification of the loop and the missing name. The operating system’s resolver, asked by the standard library for “localhost”, answered 127.0.0.1, the real loopback address, which shows what the same lookup looks like in a real program. A resolver for real domains needs the network, so this lesson works on a zone that it carries with it.

Check by hand: the shop name is a CNAME with TTL 300 to shop.builder-b.example, which has an A record of 198.51.100.99 and TTL 600, and the smaller of the two, 300 seconds, is the longest that a cached copy of the whole answer can live. So a change to that record can take up to about 300 seconds, or 5 minutes, to be seen everywhere, while a change to www could take up to 600 seconds, 10 minutes, because the builder’s own record has the larger lifetime.

Do not delete working records while you change

Before you switch a domain to a new builder, note down the old records, especially MX records for email. Deleting them by mistake stops your email, and a typo in a TXT record can break email delivery.

Lower the TTL before a move

A day before you change the address of a busy site, lower the TTL of the record to 300 seconds. After the change has settled, raise it again. Then the switch takes minutes and not hours.

About this course

Builders, plans and prices change often, so the lessons use generic labels such as Builder A and describe categories of tools, and you must check each vendor’s current website for features, prices and limits. Every calculation and check in this lesson was run while the course was written, in Python 3.13 or Node.js 22, on sample data that the lesson provides, with a second independent calculation. DNS record formats differ slightly between registrars, and some use their own names for alias records. Follow the instructions of the registrar and the builder.

Practice

Write the zone for your own domain with a bare-domain address, a www alias, an MX pair and a TXT record. Add a loop on purpose and see what the resolver reports. Compute how long a change to a record with a TTL of one day can take.

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

What does a CNAME record do?

  1. Maps a name to an IPv4 address
  2. Makes one name an alias of another
  3. Names a mail server
  4. Stores text

The resolver looks up the other name.

Which MX record is tried first?

  1. The one with the lower number
  2. The one with the higher number
  3. The newest
  4. The longest name

Priority.

What does TTL mean?

  1. How long an answer may be cached, in seconds
  2. The number of records
  3. The speed of the server
  4. The size of the zone

It decides how fast changes spread.

Why is a CNAME at the apex not allowed?

  1. CNAME is deprecated
  2. Builders forbid it
  3. It is slow
  4. The apex needs other records such as MX and NS

A name with a CNAME may have no other records.

What is NXDOMAIN?

  1. A server error
  2. A loop
  3. A slow answer
  4. The name does not exist

Often a typo in a record.

Summary

  • A domain name is turned into an address by DNS records in your zone.
  • A, CNAME, MX and TXT cover most cases.
  • TTL decides how long old answers live in caches.
  • Follow the builder’s instructions, and keep a copy of old records.

Next lesson

Lesson 6 covers search engine basics.

Questions

How long does it take for a new domain to work?

Often minutes, sometimes up to a day, because of caching. If it fails for longer, check the records against your builder's instructions.

Should I register the domain with my builder?

It is convenient, and it also ties you to that builder's prices. Registering with an independent registrar keeps the domain in your hands. Check each one's current terms.

What are SPF, DKIM and DMARC?

Email authentication records, published in DNS, that help mail providers trust your messages. Your email provider's instructions give the exact records.

Progress is saved in this browser.