<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 7/19/2010 5:12 AM, Zhang Meng wrote:
<blockquote
cite="mid:AANLkTimaugaMhwWuOpLnTvSaaAqi-0TVwd2ViuUUbcod@mail.gmail.com"
type="cite">
<div><br>
</div>
<div>The question is given that</div>
<div><br>
</div>
<div>When I ask the bind server, what's the A record of <a
moz-do-not-send="true" href="http://google.com">google.com</a>?</div>
<div><br>
</div>
for the ROOT name server, there're several NS record
<div><br>
<div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://g.root-servers.net">g.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://b.root-servers.net">b.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://m.root-servers.net">m.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://d.root-servers.net">d.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://j.root-servers.net">j.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://c.root-servers.net">c.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://i.root-servers.net">i.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://a.root-servers.net">a.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://h.root-servers.net">h.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://k.root-servers.net">k.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://l.root-servers.net">l.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://f.root-servers.net">f.root-servers.net</a>.</i></div>
<div><i>.</i><span class="Apple-tab-span" style="white-space: pre;"><i>
</i></span><i>60493</i><span class="Apple-tab-span"
style="white-space: pre;"><i> </i></span><i>IN</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i>NS</i><span
class="Apple-tab-span" style="white-space: pre;"><i> </i></span><i><a
moz-do-not-send="true" href="http://e.root-servers.net">e.root-servers.net</a>.</i></div>
</div>
<div><br>
</div>
<div>How does the bind handle these multiple NS records?<br>
<div>
<div><br>
</div>
<div>A).Select one of them to ask the NS records for com. ? </div>
</div>
</div>
</div>
</blockquote>
<br>
Yes, one of them will be selected either because it has a recorded
history (based on RTT = Round Trip Time) of responding faster than
others, or at random, if there is no history, or insufficient history,
because named just started up, or some combination of the two factors,
because the RTT calculations are grouped together in "bands" and
additionally there is some random "jitter" applied so that named can
adapt to changing network conditions.<br>
<br>
<blockquote
cite="mid:AANLkTimaugaMhwWuOpLnTvSaaAqi-0TVwd2ViuUUbcod@mail.gmail.com"
type="cite">
<div>
<div>
<div>
<div>If fails, try the second one?</div>
</div>
</div>
</div>
</blockquote>
<br>
If that query fails, that particular target nameserver will be
penalized so that it is less likely to be used for a while, and some
other nameserver will be selected, using the same criteria, i.e. by
recorded RTT, with perhaps random variation due to "banding" and/or
jitter.<br>
<br>
Note that if you're ultimately trying to resolve "google.com" your
queries would generally be only for "google.com" and not ancestors of
that name, such as "com". The only exceptions would be if
(hypothetically) google.com were an alias to something else, in which
case the lookup would be "restarted" with that other name, if "glue
records" need to be resolved while following down the delegation chain,
or if you're doing DNSSEC validation and need to fetch keys/signatures.<br>
<br>
<blockquote
cite="mid:AANLkTimaugaMhwWuOpLnTvSaaAqi-0TVwd2ViuUUbcod@mail.gmail.com"
type="cite">
<div>
<div>
<div>
<div>B).Or send several queries concurrently, and get the first one
responsed?</div>
</div>
</div>
</div>
</blockquote>
No, that would be very wasteful of Internet DNS infrastructure
resources.<br>
<br>
The failover from one nameserver target to another is quite fast
(measured typically in milliseconds), but the queries are not sent
*simultaneously*. This quick-failover strategy provides a good balance
between query efficiency and resiliency.<br>
<blockquote
cite="mid:AANLkTimaugaMhwWuOpLnTvSaaAqi-0TVwd2ViuUUbcod@mail.gmail.com"
type="cite">
<div>
<div>
<div>
<div><br>
</div>
<div><br>
</div>
<div>Could you show me the related code in Bind9.7.1-P2?<br
clear="all">
<br>
</div>
</div>
</div>
</div>
</blockquote>
The code to do _what_, specifically? I suspect the resolution process
is a little more complex than you originally thought, and the code
doesn't exactly help to clarify things either, since it includes a lot
of "housekeeping" junk, e.g. memory management, quotas, task control,
locking, key-generation/validation, socket management, etc. If you're
interested in specifically the routine that sorts the candidate
nameservers according to their RTT values (with some random "jitter"
applied), take a look at sort_finds() and/or sort_adbfind() in
lib/dns/resolver.c. But all you'll really see there is (according to
the comments) "Lame N^2 bubble sort"s. The real "magic" is in how named
records those RTTs on every query it generates (see
dns_adb_adjustsrtt() in lib/dns/adb.c for some of the specifics), and
this is something that is defined in the protocol specification, not
just some nifty piece of code that's part of BIND. You might be better
served by reading some more high-level, abstract explanations of how
DNS resolution works, instead of, or at least in preparation for
staring at disparate chunks of BIND code.<br>
<br>
- Kevin<br>
<br>
</body>
</html>