Web servers and networking · Intermediate · 18 min
Understand DNS TTLs and propagation with your own resolver
By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · BIND 9.20.24 · Unbound 1.24.2
You will run BIND as the authoritative server for a practice zone and Unbound as a caching resolver in front of it, and watch cached answers, old and negative, expire on their TTLs.
On this page
You change an A record, and some people reach the new server while others still land on the old one for an hour. This is usually called DNS propagation, as if the change were spreading outwards. Nothing spreads. Your DNS provider serves the new value the moment you save it. What you are waiting for is every resolver in the world that already asked, and cached the old answer, to let its copy expire. The record's TTL (time to live, in seconds) sets how long that can take.
The clearest way to see this is to run both halves yourself. In this tutorial you run BIND as the authoritative server for a practice zone, shop.test, and Unbound as a caching resolver in front of it, both on your own machine. Then you watch TTLs count down, change a record and see the resolver keep the old value, see a "does not exist" answer get cached too, and use what you learn to plan a real migration. The .test name is reserved, so nothing you do here touches a real domain.
Step 1 · Install BIND, Unbound and dig
Install the three packages: bind9 (the authoritative server, whose program is named), unbound (the caching resolver) and bind9-dnsutils (for dig).
sudo apt-get update
sudo apt-get install -y bind9 unbound bind9-dnsutilsBoth servers start as soon as they are installed, and both try to listen on port 53 at 127.0.0.1. If the install reports that unbound failed to start, that is the clash. The next two steps move each server to its own port, so it goes away.
Before you change anything, keep copies of the two BIND files this tutorial edits, so you can put them back at the end:
sudo cp /etc/bind/named.conf.options /etc/bind/named.conf.options.orig
sudo cp /etc/bind/named.conf.local /etc/bind/named.conf.local.origCheck it worked
dig -v
unbound -V | head -n 1The first line prints something like DiG 9.20.24-1ubuntu0.5-Ubuntu, the second Version 1.24.2. Later point releases are fine.
Step 2 · Serve a practice zone with BIND
An authoritative server holds the zone file, the source of truth for a domain. It does not cache other people's answers and does not look anything up for clients. That is the resolver's job.
The next command replaces Ubuntu's named.conf.options (you saved a copy in the last step). The new options make BIND listen only on 127.0.0.1 port 5300, answer only for its own zones, and refuse recursive lookups.
sudo tee /etc/bind/named.conf.options > /dev/null <<'EOF'
options {
directory "/var/cache/bind";
listen-on port 5300 { 127.0.0.1; };
listen-on-v6 { none; };
recursion no;
allow-query { 127.0.0.1; };
};
EOFAdd the practice zone to named.conf.local:
sudo tee -a /etc/bind/named.conf.local > /dev/null <<'EOF'
zone "shop.test" {
type primary;
file "/etc/bind/db.shop.test";
};
EOFNow write the zone file. $TTL 60 gives every record a 60-second TTL unless the record sets its own. The last number in the SOA record, 30, matters later: it caps how long a resolver may remember that a name does not exist.
sudo tee /etc/bind/db.shop.test > /dev/null <<'EOF'
$TTL 60
@ IN SOA ns1.shop.test. hostmaster.shop.test. (
1 ; serial, raise it on every change
3600 ; refresh
600 ; retry
86400 ; expire
30 ) ; negative-caching TTL
IN NS ns1.shop.test.
ns1 IN A 127.0.0.1
www IN A 192.0.2.10
EOF
sudo named-checkconf
sudo named-checkzone shop.test /etc/bind/db.shop.testnamed-checkconf prints nothing when the configuration is valid. named-checkzone ends with loaded serial 1 and OK. The address 192.0.2.10 is from a range kept for documentation, so it points at nothing real.
Restart BIND so it reads the new configuration:
sudo systemctl restart namedCheck it worked
Ask BIND directly. @127.0.0.1 -p 5300 sends the question to that address and port.
dig @127.0.0.1 -p 5300 www.shop.test A +noall +answer
dig @127.0.0.1 -p 5300 www.shop.test A | grep 'flags:'The answer line is www.shop.test. 60 IN A 192.0.2.10, and the flags line includes aa, an authoritative answer. Run the first command a few times: the TTL is always 60. An authoritative server hands out the full TTL every time, because it is not counting anything down.
Step 3 · Put Unbound in front as a caching resolver
This is the kind of server your laptop and phone use every day: your ISP's resolver, your mobile operator's, or a public one. It takes a question, finds the authoritative server, asks it, and keeps the answer until the TTL runs out.
Create a configuration file of your own in Unbound's include folder. It listens on 127.0.0.1 port 5301 and sends every shop.test question to BIND on port 5300.
sudo tee /etc/unbound/unbound.conf.d/ttl-demo.conf > /dev/null <<'EOF'
server:
interface: 127.0.0.1@5301
access-control: 127.0.0.0/8 allow
do-not-query-localhost: no
local-zone: "test." nodefault
domain-insecure: "shop.test"
stub-zone:
name: "shop.test"
stub-addr: 127.0.0.1@5300
EOF
sudo unbound-checkconfEach line has a reason:
do-not-query-localhost: no: Unbound normally refuses to send questions to127.0.0.1, and BIND lives there.local-zone: "test." nodefault: Unbound answers every.testname itself with "does not exist", because.testis reserved. This turns that off so the stub zone is used.domain-insecure: "shop.test": Ubuntu's Unbound checks DNSSEC signatures. The practice zone is not signed, so without this line every answer would fail withSERVFAIL.stub-zone: forshop.test, ask this server directly instead of starting from the root.
unbound-checkconf prints unbound-checkconf: no errors in /etc/unbound/unbound.conf. Restart Unbound:
sudo systemctl restart unboundCheck it worked
dig @127.0.0.1 -p 5301 www.shop.test A +noall +answer
dig @127.0.0.1 -p 5301 www.shop.test A | grep 'flags:'The answer is the same address, 192.0.2.10. The flags line now has rd ra (recursion asked for and available) and no aa: Unbound is not the owner of the zone, it is passing on what BIND told it.
Step 4 · Watch the TTL count down
Ask the resolver twice, ten seconds apart:
dig @127.0.0.1 -p 5301 www.shop.test A +noall +answer
sleep 10
dig @127.0.0.1 -p 5301 www.shop.test A +noall +answerThe second TTL is about ten lower than the first, for example 52 and then 42. The TTL in a resolver's answer is the time left on its cached copy, not the value in the zone. Every client that asks this resolver in the next 42 seconds gets the cached copy, and BIND never hears about them.
This explains a common surprise: two people look up the same name at the same moment and see different TTLs, because they use different resolvers that filled their caches at different times.
Check it worked
Store the two TTLs and compare them:
first=$(dig @127.0.0.1 -p 5301 www.shop.test A +noall +answer | awk '{print $2}')
sleep 3
second=$(dig @127.0.0.1 -p 5301 www.shop.test A +noall +answer | awk '{print $2}')
echo "TTL went from $first to $second"
if [ "$second" -lt "$first" ]; then echo "The resolver is counting down"; else echo "The TTL did not drop"; false; fiThe last line is The resolver is counting down. If it says the TTL did not drop, the cached copy most likely expired between the two queries and was fetched again; run the block once more.
Step 5 · Change a record and watch the resolver keep the old one
Move www to a new address, 192.0.2.20, and raise the serial to 2. The command rewrites the whole zone file:
sudo tee /etc/bind/db.shop.test > /dev/null <<'EOF'
$TTL 60
@ IN SOA ns1.shop.test. hostmaster.shop.test. (
2 ; serial, raise it on every change
3600 ; refresh
600 ; retry
86400 ; expire
30 ) ; negative-caching TTL
IN NS ns1.shop.test.
ns1 IN A 127.0.0.1
www IN A 192.0.2.20
EOF
sudo named-checkzone shop.test /etc/bind/db.shop.test
sudo rndc reload shop.testrndc reload prints something like zone reload queued. The serial matters on real setups: secondary name servers only fetch a new copy of the zone when the serial goes up.
Now ask both servers:
dig @127.0.0.1 -p 5300 www.shop.test A +short
dig @127.0.0.1 -p 5301 www.shop.test A +noall +answerBIND says 192.0.2.20. Unbound still says 192.0.2.10, with whatever is left of its TTL. Both are behaving correctly. This gap is everything people mean by propagation.
Watch the resolver until it changes its mind. The loop asks every five seconds, for up to 70 seconds:
for i in $(seq 1 14); do
answer=$(dig @127.0.0.1 -p 5301 www.shop.test A +short)
echo "$(date +%T) resolver says $answer"
if [ "$answer" = "192.0.2.20" ]; then break; fi
sleep 5
doneCheck it worked
The loop prints the old address a few times, then 192.0.2.20, within 60 seconds of the resolver first caching the record. Confirm the resolver now matches BIND:
if [ "$(dig @127.0.0.1 -p 5301 www.shop.test A +short)" = "192.0.2.20" ]; then echo "Resolver has the new address"; else echo "Resolver still has the old address"; false; fiStep 6 · See negative caching from the SOA
Resolvers also cache "this name does not exist". Ask for a name the zone does not have:
dig @127.0.0.1 -p 5301 new.shop.test A +noall +comments +authority | grep -E 'status:|SOA'You see status: NXDOMAIN and the zone's SOA record in the authority section, with a TTL of 30 or a little less. That TTL is how long the "no" is cached. It is the lower of the SOA record's own TTL (60 here) and the last number in the SOA (30 here).
Now create the name. Rewrite the zone with a new record and serial 3:
sudo tee /etc/bind/db.shop.test > /dev/null <<'EOF'
$TTL 60
@ IN SOA ns1.shop.test. hostmaster.shop.test. (
3 ; serial, raise it on every change
3600 ; refresh
600 ; retry
86400 ; expire
30 ) ; negative-caching TTL
IN NS ns1.shop.test.
ns1 IN A 127.0.0.1
www IN A 192.0.2.20
new IN A 192.0.2.30
EOF
sudo named-checkzone shop.test /etc/bind/db.shop.test
sudo rndc reload shop.testAsk the resolver again straight away:
dig @127.0.0.1 -p 5301 new.shop.test A +noall +comments +authority | grep -E 'status:|SOA'It still says NXDOMAIN, now with a smaller TTL on the SOA. This is why a brand-new subdomain sometimes "does not exist" for a while: someone, or some tool, asked for it before you created it, and the resolver remembered the answer. A large last number in your SOA makes that wait longer. Values between 300 and 3600 are common.
Check it worked
Wait for the cached "no" to run out:
for i in $(seq 1 10); do
answer=$(dig @127.0.0.1 -p 5301 new.shop.test A +short)
echo "$(date +%T) resolver says ${answer:-nothing}"
if [ "$answer" = "192.0.2.30" ]; then break; fi
sleep 5
done
if [ "$(dig @127.0.0.1 -p 5301 new.shop.test A +short)" = "192.0.2.30" ]; then echo "new.shop.test resolves"; else echo "Still cached as missing"; false; fiWithin about 30 seconds the resolver prints 192.0.2.30, and the last line is new.shop.test resolves.
Step 7 · Plan a migration by lowering the TTL first
You now know what decides the wait after a change: the TTL that resolvers cached before the change. Lowering the TTL at the same moment as changing the address does not help, because the copies already out there carry the old, long TTL. So the plan has three moves:
- A day before (or at least one old TTL before), lower the record's TTL, for example from 3600 to 300.
- Make the change. Resolvers now hold copies for at most 300 seconds, so the switch is over within about five minutes. Keep the old server answering until then.
- Once the new server is stable, raise the TTL again. Long TTLs mean fewer lookups and faster page loads for repeat visitors.
Practise move 1 on www. Give it its own TTL of 10 seconds and raise the serial to 4:
sudo tee /etc/bind/db.shop.test > /dev/null <<'EOF'
$TTL 60
@ IN SOA ns1.shop.test. hostmaster.shop.test. (
4 ; serial, raise it on every change
3600 ; refresh
600 ; retry
86400 ; expire
30 ) ; negative-caching TTL
IN NS ns1.shop.test.
ns1 IN A 127.0.0.1
www 10 IN A 192.0.2.20
new IN A 192.0.2.30
EOF
sudo named-checkzone shop.test /etc/bind/db.shop.test
sudo rndc reload shop.testBIND publishes the new TTL at once. Unbound may still hold the copy it fetched with TTL 60. On a resolver you run, you can drop a cached name instead of waiting:
dig @127.0.0.1 -p 5300 www.shop.test A +noall +answer
sudo unbound-control flush www.shop.test
dig @127.0.0.1 -p 5301 www.shop.test A +noall +answerunbound-control flush prints ok. You cannot do this for anyone else's resolver: not your visitors' ISPs, not the resolver on a mobile network. Across much of Africa most visitors browse on mobile data, through their operator's resolver, and those caches are out of your reach. Lowering the TTL in advance is the only control you have over them.
Two more limits to plan around. A resolver may cap TTLs: Unbound, by default, keeps nothing longer than one day (cache-max-ttl 86400) and can be set to keep answers for a minimum time (cache-min-ttl, off by default), so a few resolvers may hold your record longer than you asked. And some apps and operating systems keep their own short-lived cache on top of the resolver's.
Check it worked
ttl=$(dig @127.0.0.1 -p 5301 www.shop.test A +noall +answer | awk '{print $2}')
echo "Resolver TTL is now $ttl"
if [ "$ttl" -le 10 ]; then echo "The short TTL is live"; else echo "The resolver still has the long TTL"; false; fiBIND shows www.shop.test. 10 IN A 192.0.2.20, and the resolver's TTL is 10 or less.
Step 8 · Ask specific servers and trace a real domain
The same habits work on real domains. Replace example.com with your own.
Find the authoritative name servers, then ask one of them directly. Its answer always carries the full TTL and the current value, with no cache in between:
dig example.com NS +short
dig @ns1.example.com example.com A +noall +answerReplace ns1.example.com with a name from the first command's output.
Then ask two public resolvers. Their TTLs usually differ, because each one filled its cache at a different time, and their answers differ during a change:
dig @1.1.1.1 example.com A +noall +answer
dig @8.8.8.8 example.com A +noall +answerTo see the whole chain from the root servers down to the authoritative server, with no resolver's cache involved, use +trace:
dig example.com A +traceThe output is something like this, shortened:
. 518400 IN NS a.root-servers.net.
;; Received 239 bytes from 127.0.0.53#53(127.0.0.53) in 4 ms
com. 172800 IN NS a.gtld-servers.net.
;; Received 1170 bytes from 198.41.0.4#53(a.root-servers.net) in 20 ms
example.com. 172800 IN NS a.iana-servers.net.
;; Received 655 bytes from 192.5.6.30#53(a.gtld-servers.net) in 30 ms
example.com. 300 IN A <address>
;; Received 56 bytes from 199.43.135.53#53(a.iana-servers.net) in 90 msRead it from the top: the root names the servers for com, those name the servers for example.com, and the last server, the authoritative one, gives the answer. The NS records at each level have their own, often long, TTLs. That is why moving a domain to a new DNS provider (changing its name servers) can take up to a day or two, even when your A records have short TTLs.
Check it worked
For your own domain, the address from dig @ns1... matches what you set at your DNS provider. If a public resolver shows something else, compare its TTL with the record's full TTL: the remaining seconds are how long it will keep the old value.
Step 9 · Clean up
Remove the practice zone and your Unbound file, and put back BIND's original files:
sudo rm /etc/unbound/unbound.conf.d/ttl-demo.conf /etc/bind/db.shop.test
sudo cp /etc/bind/named.conf.options.orig /etc/bind/named.conf.options
sudo cp /etc/bind/named.conf.local.orig /etc/bind/named.conf.local
sudo rm /etc/bind/named.conf.options.orig /etc/bind/named.conf.local.origIf you installed BIND and Unbound only for this tutorial, stop them and keep them from starting at boot:
sudo systemctl disable --now named unboundTo remove them completely, run sudo apt purge bind9 unbound.
Check it worked
systemctl is-active named unboundIt prints inactive twice, and dig @127.0.0.1 -p 5301 www.shop.test ends with no servers could be reached.
Next steps
- Review what each record type does, with the same dig habits: /tutorials/dns-records-explained-a-cname-mx-txt
- Find out whether a slow page is DNS, TCP, TLS or the app: /tutorials/debug-a-slow-or-failing-website-with-curl
- Use a TXT record and short TTLs to prove domain control for a wildcard certificate: /tutorials/get-a-wildcard-certificate-with-a-dns-01-challenge
Related tutorials
- Write Nginx location blocks that match what you expectYou will build a practice Nginx 1.30 server where every location block labels its responses, predict which block answers each of twelve URLs, check your answers with curl, and fix the alias, regex-order and proxy_pass mistakes that catch most people out.
- Write a server firewall with nftablesYou will write one /etc/nftables.conf with a default-drop input chain, rate-limited SSH, named address sets, counters and logging, and load it over SSH behind a timer that undoes it if you lose your connection.
- Watch a TCP connection open and close with tcpdumpYou will capture a curl request to a local web server with tcpdump on Ubuntu 26.04, read its handshake, data and teardown line by line, see the reset a closed port sends, and save, filter and rotate captures as pcap files.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials