Platform Engineering · Lesson 110

Internet Plumbing: DNS Delegation, Split-Horizon DNS, BGP, Anycast, and Clock Skew

Some infrastructure is so basic that it is noticed only when it breaks, and then everything breaks. DNS delegation hands a zone from a parent to child name servers with NS and glue records; split-horizon DNS answers the same name differently inside and outside a network. BGP is how networks tell each other which addresses they can reach; anycast announces the same address from many places so users reach the nearest. And time: NTP (or PTP) keeps clocks in step, because TLS certificates, tokens, logs, and distributed databases all assume clocks agree. This lesson follows one user's request to an anycast DNS and API service, and shows two failures: a delegation change that broke resolution for a day, and a clock that drifted until tokens were rejected.

Difficulty: Advanced · Know this first: Lesson 105, Lesson 61

What you will learn

By the end of this lesson you can work at four levels:

This page teaches it with a plain-language analogy, an animated diagram with normal and failure scenarios, a simulator, a quiz, basic, intermediate, advanced, and master checks, the expert detail ("Go deeper"), a production incident, a hands-on lab with commands and their output, and a production design exercise.

Run it as:

When it breaks, I check

One thing to remember

Where the time goes

This bar adds up minutes of user-visible disruption. It is a worked example, not a measurement. The delegation and time hops are where small infrastructure mistakes become large outages.

Try it: migrate DNS and keep time

Pick how a DNS provider migration is done, how sites announce the anycast address, and whether time sync is monitored.

0 minDNS disruption
secondsusers stuck on a failed site
2 msworst clock offset

Check yourself

Three questions. No score is saved anywhere — this is just you against the material.

Basic to master

Infrastructure plumbing grows in four levels: tracing a name and a route, operating DNS and time, running anycast and BGP, and designing it for resilience.

Basic — Trace a name and a route

At the basic level you can follow a name to an address and a packet to a site.

  • dig +trace, NS, glue, TTLs; inside versus outside answers.
  • Anycast, BGP prefixes, and AS paths in a looking glass.
  • Clock offset with chronyc tracking or timedatectl.

Where it breaks: testing DNS from inside only, when the problem is the public view (or the reverse).

Try it: Basic

Staff cannot reach a new service; customers can. What is the likely cause?

Now do it: Resolve one name from both sides.

Intermediate — Operate DNS and time

At the intermediate level you change DNS and run time sync safely.

  • Lower TTLs before changes; staged provider migrations; parent last.
  • Both views generated from one source (for example, one Terraform module with two outputs).
  • chrony on every image, several sources, offset alerts.

Try it: Intermediate

You will change an A record tomorrow. What do you do today?

Now do it: Check the TTL of one record you will change soon.

Advanced — Run anycast and BGP

At the advanced level you announce and protect your own routes.

  • Announcements tied to health checks; drills that withdraw a site.
  • RPKI ROAs for your prefixes; route filtering with peers.
  • BGP in the data centre fabric and for Kubernetes load balancer IPs (MetalLB, Calico).

Try it: Advanced

What does an RPKI ROA let other networks do?

Now do it: Check your prefixes' RPKI status.

Master — Design for resilience

At the master level the plumbing has no single point of failure.

  • Authoritative DNS on two independent providers; secondary zones kept in sync.
  • Anycast across many sites with capacity for a site loss; DDoS absorption.
  • Time from multiple independent sources; PTP where ordering needs microseconds.

Trade-off: two DNS providers double the configuration to keep in step; automation from one source removes the risk of drift.

Try it: Master

Why run authoritative DNS on two providers?

Now do it: List your authoritative name servers and their providers.

Go deeper

Read-only checks for delegation, split-horizon, routing, and time:

dig +trace api.example.com                               # root → .com → example.com, step by step
dig +short NS example.com @a.gtld-servers.net            # what the parent says (delegation)
dig +short NS example.com @ns1.example.com               # what the child says: should match
dig +norecurse example.com SOA @ns1.newprovider.net      # does the new provider answer authoritatively?
dig +short api.example.com @10.0.0.2                     # internal view (VPC resolver)
dig +short api.example.com @1.1.1.1                      # public view
whois -h whois.radb.net 203.0.113.0/24                   # registered route objects
chronyc tracking                                         # "System time" offset from the reference
chronyc sources -v                                       # which servers chrony is using, and their quality
timedatectl show-timesync --all 2>/dev/null              # systemd-timesyncd, where used

A safe DNS provider migration: lower the TTLs of the NS records you control and of key records; export the zone and load it on the new provider; verify every record from the new servers directly; add the new name servers alongside the old ones at the registrar and in the zone; wait at least the parent's NS TTL (two days for .com); remove the old ones from the registrar, then from the zone; keep the old provider serving for another TTL.

Kubernetes and clocks: nodes need time sync like any host; TLS between control plane components, service account tokens (with nbf and exp), and etcd leases all assume it. Many managed platforms configure it for you; custom images must enable it.

One time it broke

This is a composite of a failure pattern that keeps repeating; the details are illustrative. The name servers that were not ready.

Timeline

  • Friday 16:00To move DNS providers, the NS records at the registrar are switched to the new provider's servers. The zone import is scheduled for "after the switch".
  • Friday 16:30Resolvers that refresh the .com delegation now ask the new servers, which answer REFUSED. Users of those resolvers cannot reach the site or its API.
  • Friday 18:00The zone is loaded on the new provider, and the NS records reverted to be safe. Resolvers that cached the new delegation keep using it for up to two days; failures fall as caches expire.
  • Saturday 16:00Most users recovered. The migration is redone the following month in stages.

What changed after

DNS changes follow a runbook (verify new servers first, add alongside, wait TTLs, remove last), the zone is managed as code and pushed to both providers, and an external check resolves key names from several public resolvers every minute.

Try it yourself, from scratch

Everything here runs on any Linux machine: your own laptop, WSL on Windows (run wsl --install in PowerShell once), or a small cloud VM. The Python needs only Python 3 and its standard library; check that you have it with python3 --version.

Before you start: Linux with dig (sudo apt install dnsutils), network access, and Python 3. Every command here is read-only.

1. Linux commands

Type each one, read what it prints, and compare it with the note above it.

  1. Follow a name from the root, the way a resolver does.

    Read-only

    dig +trace +nodnssec example.com | grep -E "IN\s+(NS|A)\s" | head -12

    Options: +trace starts at the root and follows each delegation.

    Expect: Root servers, then .com servers, then example.com's name servers, then the answer. Read-only.

  2. Compare the delegation at the parent with the child's own NS records; they should match.

    Read-only

    PARENT=$(dig +short NS com | head -1)
    echo "parent says:"; dig +short +norecurse NS example.com @"$PARENT" | sort
    echo "child says:";  dig +short NS example.com @"$(dig +short NS example.com | head -1)" | sort

    Options: +norecurse asks the .com server for its own data; the delegation appears in the authority section, so +short may print it only on some versions; use dig NS example.com @"$PARENT" +norecurse to see the full answer.

    Expect: The same name servers from both, or a mismatch worth fixing. Read-only.

  3. Look at the TTLs that decide how long a mistake lasts.

    Read-only

    dig +noall +answer +authority NS example.com @"$(dig +short NS com | head -1)" +norecurse | awk '{print $2, $4, $5}'

    Expect: NS records with their TTL in seconds (172800, two days, for .com delegations). Read-only.

  4. Check this machine's clock against its time sources.

    Read-only

    chronyc tracking 2>/dev/null | grep -E "System time|Leap" || timedatectl status | grep -Ei "synchronized|NTP"

    Expect: The offset from the reference (for example "0.000412 seconds fast") or the systemd sync status. Read-only.

    Clean up: nothing to clean up: every step only reads, and nothing was created or changed.

2. Python: plumbing.py

This program simulates a DNS provider migration as resolvers see it, with delegations cached for the parent's two-day TTL, comparing a one-step switch with a staged one. Then it validates tokens issued by hosts with different clock offsets against a 30-second leeway, the way clock skew turns into intermittent rejections. Save it as plumbing.py, then run it.

# plumbing.py
TTL_H = 48                                   # .com delegations are cached for two days
WINDOW_H = 2                                 # hours the new servers were listed but could not answer
RESOLVERS = 10_000                           # resolvers that look up the domain, refreshing at random times

def affected(hours_after, plan):
    if plan == "staged":
        return 0                             # new servers answer before they are listed; old ones stay up
    cached_bad = RESOLVERS * min(hours_after, WINDOW_H) / TTL_H
    if hours_after <= TTL_H:
        return round(cached_bad)
    return round(cached_bad * max(0.0, 1 - (hours_after - TTL_H) / WINDOW_H))

print("hours after the change   one-step switch: resolvers failing   staged: resolvers failing")
for h in (1, 2, 12, 24, 48, 49, 50):
    print(f"{h:>21}   {affected(h, 'switch'):>33,}   {affected(h, 'staged'):>24,}")
print(f"a resolver that cached the bad delegation keeps it for up to {TTL_H} h, whatever you fix in the meantime")
print()

LEEWAY = 30
HOSTS = {"node-a": 0.4, "node-b": -1.2, "node-new-1": 240.0, "node-new-2": 238.5}   # clock offset, seconds
for issuer, offset in HOSTS.items():
    issued_at = 1_000_000 + offset            # the issuer stamps its own (possibly wrong) time
    now_at_verifier = 1_000_000                # the verifier's clock is right
    if issued_at - now_at_verifier > LEEWAY:
        verdict = f"REJECTED: not yet valid ({issued_at - now_at_verifier:.0f} s in the future)"
    else:
        verdict = "accepted"
    print(f"token from {issuer:<11} offset {offset:+7.1f} s  {verdict}")

Run it, and you should see this output:

$ python3 plumbing.py
hours after the change   one-step switch: resolvers failing   staged: resolvers failing
                    1                                 208                          0
                    2                                 417                          0
                   12                                 417                          0
                   24                                 417                          0
                   48                                 417                          0
                   49                                 208                          0
                   50                                   0                          0
a resolver that cached the bad delegation keeps it for up to 48 h, whatever you fix in the meantime

token from node-a      offset    +0.4 s  accepted
token from node-b      offset    -1.2 s  accepted
token from node-new-1  offset  +240.0 s  REJECTED: not yet valid (240 s in the future)
token from node-new-2  offset  +238.5 s  REJECTED: not yet valid (238 s in the future)

3. What to notice

4. Advanced: every step as one Bash script

The same Linux steps, made into a real script you can keep and run again. It uses the Bash features a production script needs: functions (one per step), an array of step names, arguments to choose steps, a case for options, exit codes recorded for each step, and a trap that prints a summary even when you stop it with Ctrl+C. Make a folder for this lesson (mkdir -p ~/labs/dns-delegation-split-horizon-bgp-anycast-and-time && cd ~/labs/dns-delegation-split-horizon-bgp-anycast-and-time) and save this as lab.sh.

#!/usr/bin/env bash
# The Linux steps of "Internet Plumbing: DNS Delegation, Split-Horizon DNS, BGP, Anycast, and Clock Skew", as one script (save it as lab.sh).
#
#   ./lab.sh          run every step, in order
#   ./lab.sh 2 4      run only steps 2 and 4
#   ./lab.sh --list   list the steps
#
# The steps share one shell, so a later step can use what an earlier one set up (a folder,
# a variable, a container): run them all in order the first time. Your own scripts should
# start with "set -euo pipefail"; this one runs teaching commands, and some of them fail on
# purpose, so it records each step's exit code instead of stopping at the first failure.

STEPS=(
  'Follow a name from the root, the way a resolver does.'
  'Compare the delegation at the parent with the child'\''s own NS records; they should match.'
  'Look at the TTLs that decide how long a mistake lasts.'
  'Check this machine'\''s clock against its time sources.'
)

step_1() {
dig +trace +nodnssec example.com | grep -E "IN\s+(NS|A)\s" | head -12
}

step_2() {
PARENT=$(dig +short NS com | head -1)
echo "parent says:"; dig +short +norecurse NS example.com @"$PARENT" | sort
echo "child says:";  dig +short NS example.com @"$(dig +short NS example.com | head -1)" | sort
}

step_3() {
dig +noall +answer +authority NS example.com @"$(dig +short NS com | head -1)" +norecurse | awk '{print $2, $4, $5}'
}

step_4() {
chronyc tracking 2>/dev/null | grep -E "System time|Leap" || timedatectl status | grep -Ei "synchronized|NTP"
}

# print a step that has to be run by hand, instead of running it
by_hand() {
  echo "  (run this one yourself: $1)"
  sed 's/^/    /'
}

RESULTS=()
run_step() {
  local n=$1 start=$SECONDS code
  printf '\n== step %d of %d: %s\n' "$n" "${#STEPS[@]}" "${STEPS[n-1]}"
  "step_$n"
  code=$?
  RESULTS+=("step $n: exit code $code, $((SECONDS - start)) s")
}

summary() {
  echo
  echo "== summary"
  local r
  for r in "${RESULTS[@]}"; do echo "  $r"; done
}

case "${1:-}" in
  -h|--help) sed -n '2,6p' "$0"; exit 0 ;;
  --list) for i in "${!STEPS[@]}"; do echo "$((i + 1)). ${STEPS[i]}"; done; exit 0 ;;
esac

[ $# -eq 0 ] && set -- $(seq 1 "${#STEPS[@]}")
for n in "$@"; do
  if ! [[ $n =~ ^[0-9]+$ ]] || (( n < 1 || n > ${#STEPS[@]} )); then
    echo "there is no step '$n'; try --list" >&2
    exit 2
  fi
done
trap summary EXIT
trap 'echo; echo "stopped with Ctrl+C"; exit 130' INT
for n in "$@"; do run_step "$n"; done

Then make it executable and run it:

chmod +x lab.sh
./lab.sh --list     # the steps
./lab.sh            # every step, then a summary of exit codes and times
./lab.sh 2 3        # only steps 2 and 3

5. Learn the basics behind it

New to a feature used above? These W3Schools pages explain each one from zero, with examples you can run in the browser.

If you remember nothing else

Design exercise

Your company serves an API to customers worldwide and runs internal services in two clouds. Design its DNS, routing, and time infrastructure for resilience.

Clarifying questions to ask

Where is authoritative DNS hosted, and how are changes made? How do internal and external views stay consistent? How do users reach the nearest healthy site? How are routes protected? How is time kept and monitored?

Rough sizing

Say 300 DNS records, 6 serving sites, 2 clouds plus a data centre, 1,500 hosts, and a token lifetime of 5 minutes.

Shape of the answer

Authoritative DNS on two providers, zone as code pushed to both, changes through a reviewed pipeline with TTL planning; split-horizon generated from the same code (private zones and resolver rules for internal names); anycast through a provider or your own ASN with health-tied announcements and site-loss drills; RPKI ROAs for owned prefixes; chrony on every image against cloud time services and internal servers, offset alerts at 100 ms, leeway of 30 seconds on token checks; external monitoring of resolution from several public resolvers.

Trade-offs to name

Two DNS providers add sync work that automation must absorb; long TTLs reduce query load and slow recovery from mistakes; anycast simplifies global routing and makes per-site capacity planning essential.

Failure modes and how to troubleshoot them

Each row is one way this system went wrong in the diagram's scenarios. The hop number is where to look first.

ScenarioWhereEffectWhat goes wrong
Broken delegationHop 2: DelegationBreaksDuring a DNS provider migration, the NS records at the registrar are switched to the new provider's servers before the zone is published there. The new servers answer REFUSED for example.com. Resolvers that refresh the delegation cache it for up to two days.
Clock driftHop 8: Time syncBreaksA new node image ships with chrony installed but disabled. Over three days the new nodes drift four minutes fast.

How to troubleshoot

  1. Write down the symptom and when it started: what users see, which number moved, and what changed just before (a deploy, a config change, traffic).
  2. Walk the path in order, from the first hop to the last: Resolver → Delegation → Split-horizon → Anycast address → BGP → Nearest site → Health withdrawal → Time sync → Token check. The first hop whose evidence is wrong is where to dig.
  3. At that hop, run the read-only check from the diagram or the lab first; change nothing until the evidence points at a cause.
  4. Fix the smallest thing that restores service, or roll back the last change, and confirm the symptom is gone with the same check.
  5. Write down what you found and the check that would have caught it sooner, so the next person starts there.

References and review

The official documentation and standards behind this lesson. Versions and defaults change; when a command or field here differs from them, trust the official page.

Last updated . Next review due by November 2027. Found something out of date? Tell me.

Saved on this device, in this browser.
Next in this series · Lesson 111
Bare-Metal Provisioning, PXE, Image Pipelines, and the Hardware Lifecycle

Clouds hide the hardware; someone still racks it, powers it, cools it, installs it, patches its firmware, and retires it. Bare-metal provisioning turns a new server into a working node without hands on a keyboard: the server…

Go to Lesson 111 →

Or browse the full course from the Lessons index.