Exercises — DNS — recursive vs iterative query, hierarchy, record types (A, AAAA, CNAME, MX, NS)
4.3.23 · D4· Coding › Computer Networks › DNS — recursive vs iterative query, hierarchy, record types
Pehli line se pehle yeh do words haath mein hone chahiye:

L1 — Recognition
Problem 1.1
Har mapping ke liye, woh single record type batao jo use store karta hai:
(a) blog.site.com → 203.0.113.7
(b) blog.site.com → 2606:4700::6810:85e5
(c) shop.site.com → naam www.site.com
(d) site.com → mail server mail.site.com preference 10 ke saath
(e) site.com → uska authoritative server ns1.site.com
Recall Solution 1.1
(a) A — ek naam se IPv4 address tak (32-bit, dotted decimal). Dekho IP Addressing — IPv4 vs IPv6. (b) AAAA — ek naam se IPv6 address tak (128-bit, colon-hex form). "Quad-A" = ek A record ke 32 bits ka chaar guna. (c) CNAME — ek alias: ek naam jo doosre naam ki taraf point karta hai, address ki taraf nahi. (d) MX — ek domain se mail exchanger tak, ek preference number le jaata hai. (e) NS — woh delegation record jo zone ke authoritative server ko naam deta hai.
Problem 1.2
True ya false, ek-line reasons ke saath:
(a) Ek root server example.com ka A record store karta hai.
(b) Tumhara laptop root server ko ek iterative query bhejta hai.
(c) MX value 10 ko 20 se zyada prefer kiya jaata hai.
Recall Solution 1.2
(a) False. Ek root server sirf yeh jaanta hai ki TLD servers kahan rehte hain (.com, .org, …). Yeh kabhi kisi individual domain ka address store nahi karta.
(b) False. Tumhara laptop kabhi root se baat hi nahi karta. Yeh apne resolver ko ek recursive query bhejta hai; resolver root/TLD/authoritative ko iterative queries bhejta hai.
(c) True. Lower preference number = pehle try kiya jaata hai = preferred. Number ko "rank" ki tarah padho, jahan #1 #2 se aage hota hai.
L2 — Application
Problem 2.1
mail.shop.example.com ki full uncached resolution ko step by step trace karo. Har arrow ko recursive ya iterative label karo aur batao har server kya reply karta hai.
Recall Solution 2.1
Naam ko right-to-left padho: root → com → example.com → shop.example.com → host mail. Upar ke figure mein arrows follow karo.
- Laptop → resolver: recursive — "
mail.shop.example.comdo mujhe, main wait karunga." - Resolver → root: iterative. Root: "Mere paas nahi hai.
.comTLD server se poochho." - Resolver →
.comTLD: iterative. TLD: "example.comke authoritative serverns1.example.comse poochho." - Resolver →
ns1.example.com: iterative. Iske paas sub-zoneshop.example.comke liye aur ek NS delegation ho sakta hai, reply karte hue "askns1.shop.example.com." - Resolver →
ns1.shop.example.com: iterative. Yehmail.shop.example.comka A record return karta hai, jaise203.0.113.55. - Resolver answer cache karta hai aur use recursively tumhare laptop ko return karta hai. Total: 1 recursive (laptop side) + 4 iterative (resolver side) hops.
Problem 2.2
Ek zone file mein hai:
example.com. IN NS ns1.example.com.
example.com. IN MX 10 mail1.example.com.
example.com. IN MX 20 mail2.example.com.
www.example.com. IN A 93.184.216.34
web.example.com. IN CNAME www.example.com.
(a) web.example.com kaunse IPv4 address pe resolve hoga, aur kitne record lookups lagte hain?
(b) Ek mail server example.com pe deliver karna chahta hai. Pehle kaunsa host try karta hai, aur agar woh host down ho, toh aage kaunsa?
Recall Solution 2.2
(a) web ek CNAME hai www ki taraf. Toh web resolve karne se pehle milta hai "canonical name hai www.example.com," phir www pe doosra lookup karta hai jo uska A record 93.184.216.34 return karta hai. Yeh 2 lookups hain: CNAME → phir A. Yahi indirection ki wajah se tum www ki IP ek baar edit karte ho aur har alias follow karta hai — dekho Caching and TTL ki wajah se inn mein se har ek separately cache hota hai.
(b) Lowest MX preference pehle: mail1 (pref 10). Agar mail1 unreachable ho, toh mail2 (pref 20) pe fall back karo. Lower number = higher preference. (Dekho SMTP and Email Delivery ki sender host pick karne ke baad kya karta hai.)
L3 — Analysis
Problem 3.1 (caching cost model)
Ek resolver queries serve karta hai jahan ek fraction uski cache se milti hai (near-zero cost) aur miss hoti hain aur unhe hops ki full resolution chahiye, har hop time costa hai. Har query ki expected cost hai aur diye hain: (a) , , ke liye average cost compute karo. (b) se jaane se average cost kitne factor se cut hoti hai?
Recall Solution 3.1
Pehle, yeh formula kyun? Yeh exactly do outcomes — hit (cost ≈ 0) ya miss (cost ) — pe ek expected value hai, unki probabilities aur se weighted. Hit term vanish ho jaati hai kyunki ek cache hit essentially free hai, sirf bachta hai. Ek full miss cost karta hai . (a)
- : .
- : .
- : . (b) Factor sasta. Caching hi woh reason hai ki DNS billions queries survive karta hai.
Problem 3.2 (ek lookup toot jaata hai)
Users report karte hain ki www.example.com "not found" hai, jabki authoritative server ke paas clearly A record hai. Diagnosis reveal karta hai: .com TLD domain ka NS ns1.example.com list karta hai, lekin koi A/AAAA record nahi hai jo kisi ko ns1.example.com khud ki IP bataye. Failure explain karo aur fix ka naam batao.
Recall Solution 3.2
Yeh classic missing glue record problem hai. Authoritative server tak pahunchne ke liye, resolver ko ns1.example.com ki IP jaanni chahiye. Lekin ns1.example.com us example.com zone ke andar rehta hai jiske liye use answer dena hai — ek chicken-and-egg loop: tumhe server ka address chahiye taaki server se uska apna address poocha ja sake.
Fix: parent (.com TLD) ko ek glue record publish karna hoga — ns1.example.com ke liye ek A/AAAA jo TLD level pe stored ho, loop todne ke liye. Glue ke bina, resolution forever circle karti hai aur timeout ho jaati hai.
L4 — Synthesis
Problem 4.1 (ek zone design karo)
startup.io ke liye minimal correct records ka set design karo taaki:
- Bare domain
startup.io(apex) website serve kare IPv4198.51.100.10pe. www.startup.iowahi site dikhaye.@startup.ioka email Google ke servers (aspmx.l.google.com, preference1) pe jaaye.- Zone
ns1.startup.ioaurns2.startup.ioserve kare.
Har record batao aur koi bhi jagah justify karo jahan tum CNAME nahi use kar sakte.
Recall Solution 4.1
startup.io. IN NS ns1.startup.io.
startup.io. IN NS ns2.startup.io.
startup.io. IN A 198.51.100.10
startup.io. IN MX 1 aspmx.l.google.com.
www.startup.io. IN CNAME startup.io.
Apex A use kyun karta hai, CNAME nahi: apex startup.io pehle se NS (aur implicit SOA) records carry karta hai. Ek CNAME ek hi naam pe kisi bhi doosre record ke saath coexist karne ki permission nahi rakhta — aur apex NS/SOA rakhne pe forced hai — toh apex pe CNAME illegal hai. Isliye hum apex ko directly IP se point karte hain A record ke saath.
www CNAME kyon use kar sakta hai: www.startup.io apna koi NS/SOA nahi rakhne wala ek ordinary sub-name hai, toh apex ki taraf CNAME bilkul theek hai, aur yeh automatically apex ki IP inherit karta hai. 198.51.100.10 ek baar change karo aur dono naam follow karte hain.
(Agar ek hosting provider tumhe apex target ke liye sirf ek naam de, toh tumhe unka ALIAS/ANAME flattening feature chahiye hoga — lekin fixed IP ke saath, plain A sabse clean hai.)
L5 — Mastery
Problem 5.1 (root under load — kyun iterative world ko bachata hai)
Maan lo poora internet (ek trillion) DNS queries per day bhejta hai. Do hypothetical worlds imagine karo:
- World A (root recursion karta hai): har query ki poori chain root server execute karta hai client ki behalf pe, toh har query root pe units of work daalta hai.
- World B (reality, iterative + caching): root sirf cache misses pe poocha jaata hai, queries ka fraction , aur aisi har query root ko sirf 1 referral unit cost karti hai (yeh point karta hai aur ruk jaata hai). ke saath: (a) Root work per day World A vs World B mein. (b) Ratio A : B. Ek sentence mein explain karo kyun iterative + caching design root ko zinda rakhta hai.
Recall Solution 5.1
World A: har query, root pe full chain: units/day. World B: sirf misses root tak pahunchti hain, har ek 1 unit cost karti hai: units/day. (a) vs . (b) Ratio . Toh real design root pe 400× kam kaam daalta hai. Ek-sentence kyun: iterative queries root ko minimum karne deti hain (ek pointer, poori chain kabhi nahi), aur caching matlab hai ki root sirf rare miss pe contact kiya jaata hai — do multiplicative savings stack hokar hundreds-fold relief banate hain, jo (anycast replication ke saath mila ke, dekho Anycast Routing) wajah hai ki 13 logical root names planet-scale traffic survive karte hain.
Problem 5.2 (end-to-end reasoning)
Tum fresh browser mein https://www.startup.io type karte ho (empty cache). DNS-relevant events ko order mein list karo jab tak browser TCP connection nahi khol leta, aur mark karo jahan Caching and TTL, CDN and Load Balancing, aur HTTP and the Web request lifecycle mein se har ek enter hota hai.
Recall Solution 5.2
- Browser stub resolver → OS cache: empty (fresh). Recursive resolver se poochho — recursive query.
- Resolver, bhi empty, iterative chain chalata hai: root →
.ioTLD →ns1.startup.ioauthoritative. www.startup.ioek CNAME hai apex ki taraf → resolver apexstartup.ioki doosri resolution karta hai → A record198.51.100.10milta hai.- Agar ek CDN aage hoti, toh authoritative answer ki jagah ek CDN hostname ki taraf CNAME ho sakta hai jiska A record geography/load se choose kiya jaata hai — yahan CDN and Load Balancing aur Anycast Routing enter hote hain.
- Resolver har record ko uske TTL ke liye cache karta hai (Caching and TTL) aur final IP recursively browser ko return karta hai.
- Browser ke paas ab IP hai → TCP+TLS connection kholta hai aur HTTP request issue karta hai — HTTP and the Web request lifecycle yahaan se sambhal leta hai.
Wrap-up Recall
Recall Ek-line answers (inhe cover karo)
- Ek CNAME kitne lookups add karta hai? ::: Ek extra (redirect, phir target resolve karo).
- Apex pe A use kyun kiya jaata hai, CNAME nahi? ::: CNAME apex ke mandatory NS/SOA records ke saath coexist nahi kar sakta.
- Agar ek in-zone name server ke paas koi glue record nahi hai toh kya toot jaata hai? ::: Ek chicken-and-egg loop; resolution kabhi server tak pahunch hi nahi sakti.
- Cache hit rate 0.9 → 0.99 karne se average cost kitne factor se cut hoti hai (H=4, t=20ms)? ::: 10×.
- Kyun iterative + caching root ko p=0.99 pe ~400× bachata hai? ::: Root ek pointer karta hai 4-hop chain ki jagah, aur sirf 1% misses pe hi.