Worked examples — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)
4.3.23 · D3· Coding › Computer Networks › DNS — recursive vs iterative query, hierarchy, record types
The scenario matrix
Kuch bhi solve karne se pehle, chalte hain har distinct case class list karte hain jo yeh topic produce kar sakta hai. Niche har worked example us cell ke saath tagged hai jo woh fill karta hai.
| Cell | Case class | Kya cheez isse different banati hai | Example |
|---|---|---|---|
| C1 | Full cache-miss (cold cache) | Har hop hona zaroori hai: root → TLD → auth | Ex 1 |
| C2 | Cache-hit (warm cache) | Zero hops — limiting "best case" | Ex 2 |
| C3 | Partial cache (mixed) | Kuch levels cached, kuch nahi — realistic middle | Ex 3 |
| C4 | Alias resolution (CNAME chain) | Answer ek name hai, IP nahi → extra lookups | Ex 4 |
| C5 | Mail routing, MX tie + fallback | Equal priorities, aur lowest-first ordering | Ex 5 |
| C6 | IPv4 vs IPv6 (A vs AAAA), both degenerates | Same name, do record types; "no AAAA" aur "only AAAA" | Ex 6 |
| C7 | Degenerate/illegal config (apex CNAME, missing glue) | Config jo kaam nahi kar sakti — pehchano aur fix karo | Ex 7 |
| C8 | Caching ka limiting behaviour (cost model ) | Scaling formula ki boundary values | Ex 8 |
| C9 | Real-world word problem (latency budget) | Ek story ko hop-counting + numbers mein convert karo | Ex 9 |
| C10 | Exam twist (TTL expiry / stale record timing) | Yeh sochna ki kab ek cache entry expire hoti hai | Ex 10 |
Har row niche cover ki gayi hai. Chalte hain.
Example 1 — Full cache-miss (Cell C1)
Forecast: padhne se pehle hops ka guess lagao. Root? TLD? Authoritative? Total kitne round trips?
- Laptop → resolver (recursive). Yeh step kyun? Tumhara laptop ek "stub" hai — woh sirf ek recursive question pooch sakta hai aur wait kar sakta hai. Yeh 1 round trip hai jo niche sab kuch wrap karta hai; yeh resolver ke internal iterative hop count mein add nahi hota.
- Resolver → root (iterative). Yeh step kyun? Empty cache matlab resolver kuch nahi jaanta, toh woh top se start karta hai. Root reply karta hai "
.comTLD se poochho." → 1 iterative hop. - Resolver → TLD
.com(iterative). Yeh step kyun? Referral yahan point karta tha. TLD reply karta hai "ns1.example.comse poochho." → 2nd iterative hop. - Resolver → authoritative (iterative). Yeh step kyun? Authoritative server actually record store karta hai. Woh reply karta hai "A =
93.184.216.34." → 3rd iterative hop. - Time count karo. resolver ke iterative hops hain (root, TLD, auth), aur 1 stub round trip add karo. Time (3 chase hops + 1 laptop hop).

Verify karo: figure mein arrows count karo — root, TLD, auth = 3 iterative arrows, plus recursive arrow laptop se/tak. , total time . Units: ms per hop × hops = ms. ✓
Example 2 — Cache-hit, the best case (Cell C2)
Forecast: is baar root/TLD/auth mein se kitno ko contact karenge?
- Laptop → resolver (recursive). Yeh step kyun? Same stub behaviour — ek recursive question. Yeh stub round trip kabhi nahi jaata: perfect cache bhi chahta hai ki tumhara laptop resolver se pooche aur jawab sune.
- Resolver pehle cache check karta hai. Yeh step kyun? Caching ka pura point yahi hai: network touch karne se pehle, locally dekho. Entry
www.example.com → 93.184.216.34present hai aur TTL > 0 hai. - Resolver turant jawab deta hai. Yeh step kyun? Koi referral chasing zaroori nahi → 0 iterative hops. Latency = sirf ek laptop↔resolver round trip .
Verify karo: iterative hops = 0 (teeno servers skip), lekin stub hop rehta hai. Latency = vs uncached — ek speedup, jo round trips ke mein collapse hone se match karta hai. ✓ Dekho Caching and TTL.
Example 3 — Partial cache, the realistic middle (Cell C3)
Forecast: kaun se levels skip hote hain — root, TLD, dono?
- Resolver cache check karta hai. Yeh step kyun? Cache sirf final answers nahi, referrals bhi store karta hai. Use milta hai "
.com→ gtld server" aur "example.com→ns1". Root aur TLD already pata hain. - Root aur TLD skip karo. Yeh step kyun? Kyunki woh referrals cached hain aur expire nahi hue, unhe dobara poochne ki koi zaroorat nahi. Yeh key insight hai: caching un names ke liye bhi help karta hai jo kabhi nahi dekhe, jab tak unke ancestors dekhe gaye hon.
- Resolver → sirf authoritative (iterative). Yeh step kyun? Sirf leaf record
blog.example.commissing hai. Ek hop use fetch karta hai. → 1 iterative hop. - Time (1 chase hop + 1 laptop hop).

Verify karo: iterative hops = 1 (vs 3 cold). Time , jo neatly cold case aur hit case ke beech baitha hai. ✓
Example 4 — Alias resolution / CNAME chain (Cell C4)
Forecast: kya ek query IP return karti hai, ya CNAME doosra lookup force karta hai? Total kitna time?
- Resolver → auth: "
ftp.example.comka A record?" Yeh step kyun? Client ek IPv4 address chahta hai, toh woh type A maangta hai. Kyunki authoritative NS already cached hai, yeh 1st iterative hop hai (root aur TLD skip hain). - Auth ek CNAME return karta hai, A nahi. Yeh step kyun?
ftpka koi A record nahi — yeh ek alias hai. Server jawab deta hai "ftpactuallywww.example.comhai," jo ek naam hai, woh number nahi jo client chahta tha. - Resolver dobara poochha: "
www.example.comka A record?" Yeh step kyun? IP abhi bhi haath mein nahi hai. Alias ko follow karna padega ek real A record tak pahunchne ke liye. Yeh 2nd iterative hop hai aur yeh93.184.216.34deta hai. (Well-behaved authoritative servers aksar target ka A usi reply mein bundle karte hain is hop ko bachane ke liye — lekin logically yeh doosra lookup hai, aur hum ise aisa hi count karte hain.) - Resolver
93.184.216.34client ko return karta hai, aur time total karta hai. Yeh step kyun? Client sirf final IP care karta tha; CNAME indirection uske liye invisible hai. Hops count karo: 2 iterative (do authoritative queries) + 1 stub round trip .

Verify karo: CNAME target www.example.com A = 93.184.216.34 resolve karta hai, toh ftp aur www same IP share karte hain. Hops = 2 iterative + 1 stub, latency . www ka A record change karna automatically ftp ko bhi move kar dega — alias ka pura point yahi hai. ✓
Example 5 — MX priority: tie + fallback (Cell C5)
Forecast: pehle kaun sa server — aur 10 par tie ka matlab kya hai?
- MX priority number ke hisaab se ascending order mein sort karo. Yeh step kyun? Chhota number = preferred (counter-intuitive lekin definition ke hisaab se — "rank #1" sochon). Toh priority 10 servers 20 se pehle aate hain. Dekho SMTP and Email Delivery.
- Priority 10 par tie ko random/round-robin se break karo. Yeh step kyun? Do equal-priority MX records ka matlab hai load share karna; sender ya toh
mail1yamail2randomly pick karta hai. Yeh mail dono mein distribute karta hai. backup(20) par tab hi fall back karo jab dono 10s fail ho jaayein. Yeh step kyun? Priority 20 last resort hai — ek lower-preference server sirf tab use hota hai jab har higher-preference wala unreachable ho.

Verify karo: ordering hai (koi bhi order, priority 10) phir backup (priority 20). Minimum priority value do mail hosts ke beech tie. Backup strictly last hai. ✓
Example 6 — A vs AAAA: both degenerate cases (Cell C6)
Forecast: kya IPv6 client hamesha IPv6 address paata hai? Kya IPv4-only client v6 tak pahunch sakta hai?
dualke liye, IPv6-preferring client pehle AAAA poochha karta hai. Yeh step kyun? Modern clients IPv6 try karte hain jab available ho. AAAA returns2001:db8::7→ IPv6 par connect. Agar woh fail hota, toh woh "Happy-Eyeballs" A record198.51.100.7par fall back karta.old(no AAAA) ke liye, client AAAA poochha karta hai aur empty answer paata hai. Yeh step kyun? Yeh degenerate "no IPv6" case hai. Empty AAAA response koi error nahi hai; bas iska matlab hai "is type ka koi record nahi." Client A record198.51.100.8par fall back karta hai — yahan ek IPv6 client bhi IPv4 use karta hai.v6(only AAAA) ke liye, IPv6 client AAAA poochha karta hai aur succeed karta hai. Yeh step kyun? Yeh symmetric "only IPv6" case hai. AAAA2001:db8::9return karta hai aur koi A fall back karne ke liye nahi hai — na hi kisi ki zaroorat hai.- Legacy IPv4-only client
v6ke liye pooche toh kuch usable nahi milta. Yeh step kyun? Woh A query karta hai, empty answer paata hai, aur AAAA use karne ke liye koi IPv6 stack nahi hai. Wohv6tak bilkul nahi pahunch sakta — yahi edge case public services ko dual-stack motivate karta hai.

Verify karo: dual → 2 address families (AAAA preferred, A backup). old → AAAA empty, A 198.51.100.8 use hota hai (1 family). v6 → AAAA 2001:db8::9, koi A nahi (1 family); ek IPv4-only client 0 usable addresses deta hai. ✓ Dekho IP Addressing — IPv4 vs IPv6.
Example 7 — Degenerate / illegal config (Cell C7)
Forecast: kaun si lines legally coexist nahi kar saktin, aur kyun?
- Line 1 — apex CNAME illegal hai. Yeh step kyun? Zone apex
example.com.mein SOA aur NS records hone zaroori hain. Ek CNAME kehta hai "main sirf ek alias hoon — mere saare doosre records ignore karo," jo required SOA/NS ke saath seedha contradict karta hai. Fix: apex par ek A/AAAA record (ya provider ka ALIAS/ANAME) use karo. - Line 2+3 — NS aur A same name par delegation clash hai. Yeh step kyun?
www.example.compar ekNSrecord us subtree ko doosre server ko delegate karta hai — matlab "mainwwwke liye jawab nahi deta." Lekin line 3 locally A record ke saathwwwke liye jawab dene ki koshish karti hai. Tum delegate karna aur khud jawab dena dono ek saath nahi kar sakte. Fix: NS drop karo agarwwwek normal host hai (A rakho), ya local A drop karo agar tum sach mein delegate kar rahe ho. - General rule batao. Yeh step kyun? CNAME kisi bhi doosre record type ke saath coexist nahi kar sakta; NS-delegation aur same name ke locally-served records mutually exclusive hain. Dono broken lines "ek authority per name/type" violate karte hain.

Verify karo: apex CNAME mandatory apex SOA/NS se conflict karta hai ⇒ illegal (parent note ki mistake #3 se match karta hai). NS + A identical name par ⇒ ambiguous authority ⇒ illegal. Do problems found. ✓
Example 8 — Limiting behaviour of the cache cost model (Cell C8)
Forecast: kaun sa limit "internet melt ho jaata hai" hai aur kaun sa "instant" hai? Aur kya sach mein 0 ms deta hai?
- Pehle samjho symbols ka kya matlab hai yahan. Yeh step kyun? Parent ka secretly stub hop include karta tha. Agar koi reader seedha is page par aaye, woh hidden convention algebra confuse kar degi. Toh is page par purely chase hops hai aur stub akela khada hai — yahi reason hai hamare formula mein standalone hai.
- Limit (kuch cached nahi). Yeh step kyun? Worst case — har query full miss hai. Total . Yeh cold-cache Ex 1 number hai: model ka upper bound.
- Limit (sab cached). Yeh step kyun? Best case — chase term vanish ho jaata hai, lekin stub hop rehta hai. Total . Yeh exactly Ex 2 se match karta hai — 0 ms nahi, kyunki tumhara laptop hamesha resolver se poochhega aur wait karega.
- Realistic . Yeh step kyun? Real resolvers ~90% hit karte hain. Total average. Chase portion ms se gir ke ms ho gaya — network work mein 10× cut — jabki fixed stub floor ms par rakhta hai. Yahi reason hai DNS scale karta hai: expensive tree-walking zyaadatar cache se serve hoti hai, sirf unavoidable stub round trip bacha rehta hai.

Verify karo: , (floor = stub hop, Ex 2 se consistent), . Total mein linear hai slope ke saath, endpoints aur . ✓
Example 9 — Real-world latency word problem (Cell C9)
Forecast: DNS wait ka bada ya chhota hissa hai?
- DNS time = (3 chase + 1 stub) × 40. Yeh step kyun? Same hop accounting Ex 1 jaisi, bas par: .
- HTTP fetch add karo. Yeh step kyun? IP pata hone ke baad hi browser connection khol sakta hai aur page request kar sakta hai. Total . Dekho HTTP and the Web request lifecycle.
- DNS fraction. Yeh step kyun? Yeh judge karne ke liye ki caching/CDN worth it hai: , matlab cold cache par ~44% wait DNS hai.
- Second visit par (cache hit), DNS stub floor ms tak gir jaata hai. Yeh step kyun? Yeh payoff dikhata hai aur Ex 8 ke floor se consistent hai: chase term disappear ho jaata hai lekin ek stub round trip rehti hai. Total ban jaata hai — sirf caching se ki bachat. Ek CDN/anycast resolver miss path aur shrink kar dega.

Verify karo: cold total ; DNS fraction ; warm total ; saving . ✓
Example 10 — Exam twist: TTL expiry timing (Cell C10)
Forecast: kya query nayi IP dekhta hai?
- Cache tak valid hai. Yeh step kyun? TTL record ki lifetime in cache hai jis moment se store hua tha. Expire hone tak, resolver cached value serve karta hai dobara pooche bina.
- par query → OLD IP. Yeh step kyun? , toh entry abhi bhi fresh hai. Admin ka par change invisible hai — resolver ne dobara check nahi kiya. Yahi reason hai DNS changes "propagate hone mein time lete hain."
- par entry expire ho jaati hai. Yeh step kyun? Ab agla query ek fresh authoritative lookup force karta hai.
- par query → NEW IP. Yeh step kyun? , cache expired, resolver authoritative se re-fetch karta hai → updated record dekhta hai. Dekho Caching and TTL.

Verify karo: expiry par. Query par: old IP. Query par: new IP. Change ke baad staleness window hai. ✓
Active Recall
Recall Answers cover karo
Cold-cache lookup with 3 iterative levels + stub round trip at 30 ms each — total? ::: ms. Same name ek second baad (cache hit) — iterative hops aur time? ::: 0 iterative hops, 30 ms (the stub floor). Ek domain mein nayi name jiska TLD+auth cached hai — iterative hops? ::: 1 (sirf authoritative). CNAME lookup with auth cached, 30 ms/hop — total latency? ::: 90 ms ((2 iterative + 1 stub) × 30). Do MX records dono priority 10 par — kya hota hai? ::: Load-shared randomly; kisi bhi priority 20 se pehle dono try hote hain. Ek host jiske paas sirf AAAA record hai — kya ek IPv4-only client us tak pahunch sakta hai? ::: Nahi — woh A query karta hai, empty milta hai, koi IPv6 stack nahi hai. s par query (TTL 300 s, s par change) OLD IP kyun return karti hai? ::: Cache abhi fresh hai (); change propagate nahi hua. Cache total-cost model at , , ms — average? ::: ms.
Recall Feynman: the coffee-shop story (Ex 9)
Pehli baar jab tum café Wi-Fi par koi site khoolte ho, tumhari wait ka ~44% sirf server dhundhne (DNS) mein jaata hai, page download karne mein nahi. Doosri baar, resolver yaad karta hai, aur dhundhna almost free hai — wait 360 ms se 240 ms tak gir jaati hai. Caching literally tumhara page load cut karta hai, aur yahi reason hai bade sites iske baare mein obsess karte hain.