4.3.23 · D3 · HinglishComputer Networks

Worked examplesDNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)

4,808 words22 min read↑ Read in English

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?

  1. 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.
  2. Resolver → root (iterative). Yeh step kyun? Empty cache matlab resolver kuch nahi jaanta, toh woh top se start karta hai. Root reply karta hai ".com TLD se poochho." → 1 iterative hop.
  3. Resolver → TLD .com (iterative). Yeh step kyun? Referral yahan point karta tha. TLD reply karta hai "ns1.example.com se poochho." → 2nd iterative hop.
  4. 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.
  5. 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).
Figure — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)

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?

  1. 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.
  2. 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.34 present hai aur TTL > 0 hai.
  3. 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?

  1. 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.comns1". Root aur TLD already pata hain.
  2. 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.
  3. Resolver → sirf authoritative (iterative). Yeh step kyun? Sirf leaf record blog.example.com missing hai. Ek hop use fetch karta hai. → 1 iterative hop.
  4. Time (1 chase hop + 1 laptop hop).
Figure — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)

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?

  1. Resolver → auth: "ftp.example.com ka 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).
  2. Auth ek CNAME return karta hai, A nahi. Yeh step kyun? ftp ka koi A record nahi — yeh ek alias hai. Server jawab deta hai "ftp actually www.example.com hai," jo ek naam hai, woh number nahi jo client chahta tha.
  3. Resolver dobara poochha: "www.example.com ka 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 yeh 93.184.216.34 deta 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.)
  4. Resolver 93.184.216.34 client 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 .
Figure — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)

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?

  1. 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.
  2. 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 mail1 ya mail2 randomly pick karta hai. Yeh mail dono mein distribute karta hai.
  3. 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.
Figure — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)

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?

  1. dual ke liye, IPv6-preferring client pehle AAAA poochha karta hai. Yeh step kyun? Modern clients IPv6 try karte hain jab available ho. AAAA returns 2001:db8::7 → IPv6 par connect. Agar woh fail hota, toh woh "Happy-Eyeballs" A record 198.51.100.7 par fall back karta.
  2. 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 record 198.51.100.8 par fall back karta hai — yahan ek IPv6 client bhi IPv4 use karta hai.
  3. v6 (only AAAA) ke liye, IPv6 client AAAA poochha karta hai aur succeed karta hai. Yeh step kyun? Yeh symmetric "only IPv6" case hai. AAAA 2001:db8::9 return karta hai aur koi A fall back karne ke liye nahi hai — na hi kisi ki zaroorat hai.
  4. Legacy IPv4-only client v6 ke 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. Woh v6 tak bilkul nahi pahunch sakta — yahi edge case public services ko dual-stack motivate karta hai.
Figure — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)

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?

  1. 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.
  2. Line 2+3 — NS aur A same name par delegation clash hai. Yeh step kyun? www.example.com par ek NS record us subtree ko doosre server ko delegate karta hai — matlab "main www ke liye jawab nahi deta." Lekin line 3 locally A record ke saath www ke liye jawab dene ki koshish karti hai. Tum delegate karna aur khud jawab dena dono ek saath nahi kar sakte. Fix: NS drop karo agar www ek normal host hai (A rakho), ya local A drop karo agar tum sach mein delegate kar rahe ho.
  3. 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.
Figure — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)

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?

  1. 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.
  2. 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.
  3. 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.
  4. 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.
Figure — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)

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?

  1. DNS time = (3 chase + 1 stub) × 40. Yeh step kyun? Same hop accounting Ex 1 jaisi, bas par: .
  2. 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.
  3. DNS fraction. Yeh step kyun? Yeh judge karne ke liye ki caching/CDN worth it hai: , matlab cold cache par ~44% wait DNS hai.
  4. 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.
Figure — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)

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?

  1. 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.
  2. 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."
  3. par entry expire ho jaati hai. Yeh step kyun? Ab agla query ek fresh authoritative lookup force karta hai.
  4. par query → NEW IP. Yeh step kyun? , cache expired, resolver authoritative se re-fetch karta hai → updated record dekhta hai. Dekho Caching and TTL.
Figure — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)

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.


Flashcards

Cold-cache resolution of a 3-level name, 30 ms/hop, including the stub round trip — total latency?
120 ms ((3 iterative + 1 stub) × 30).
Ek resolver ke paas TLD aur authoritative NS cached hai lekin leaf record nahi — us domain mein nayi name ke liye kitne iterative hops?
1 (sirf authoritative).
Jab ek authoritative server requested A record ki jagah CNAME return kare, resolver ko kya karna chahiye?
Alias follow karo aur CNAME target ka A record lookup karo.
CNAME lookup with authoritative NS already cached, 30 ms/hop — total latency?
90 ms ((2 iterative + 1 stub) × 30).
Do MX records equal priority 10 ke saath — kaise use hote hain?
Load-shared (random/round-robin); dono kisi bhi higher (bade) priority value se preferred hain.
Ek IPv6 client ek aisi name query kare jiske paas sirf A record hai — kya hota hai?
AAAA empty return karta hai (koi error nahi); client IPv4 A record par fall back karta hai.
Ek host ke paas sirf AAAA record hai — kya ek legacy IPv4-only client us tak pahunch sakta hai?
Nahi; use empty A answer milta hai aur AAAA use karne ke liye koi IPv6 stack nahi hai.
Apex CNAME illegal kyun hai?
CNAME doosre records ke saath coexist nahi kar sakta, lekin apex mein SOA aur NS records hone zaroori hain.
Record TTL 300 s, par cached, IP s par change — s par query kaun sa IP paata hai?
OLD IP (cache s tak fresh rehta hai).
Cold page load: DNS 160 ms + HTTP 200 ms — total time-to-first-byte aur DNS fraction?
360 ms total; DNS hai.
Cache total-cost model at , , ms — average latency?
39 ms (30 stub floor + 9 chase).