在CAP理论中,DNS占据了AP(Availability & partition).
按照数据库的思想来说,DNS可以说是分布式的,层次结构的,KEY-VALUE的,高可用的系统。
分布式和层次结构

网址www.yumianfeilong.com,其实就是www.yumianfeilong.com. (末尾有个”.”,表示root). “.”就是Root, “.com”就是TLD DNS, ”.com.yumianfeilong“是次级DNS. “www”可以说是该次级DNS内的一台server。
每个层次的DNS存储下一级DNS的地址。这样当要查找一个DNS对应的IP时候,可以查找root dns得到下一级DNS,再去下一级DNS递归查找。
分布式查询

DNS查询最常见的2种方式:Recursive queries:和Iterative (or nonrecursive) queries。如上为Recursive模式,表示为客户端的DNS解析完全由DNS resolve代劳,具体步骤如下:
1. A user types the URL http://www.example.com into a browser.
2. The browser sends a request for the IP address of www.example.com to its local
resolver (stub-resolver).
3. The stub-resolver queries the locally configured DNS Resolver for the IP
address of www.example.com.
4. The DNS Resolver looks up www.example.com in local tables (its cache), but it
isn’t found.
5. The DNS Resolver sends a query to a root-server for the IP (the A RR) of
www.example.com.
6. The root-server only supports iterative (nonrecursive) queries (see the
upcoming section “Iterative (Nonrecursive) Queries”) and answers with a list of
name servers that are authoritative for the next level in the domain name
hierarchy, which in this case is the gTLD .com (this is called a referral).
7. The DNS Resolver selects one of the authoritative gTLD servers received in the
previous referral and sends it a query for the IP of www.example.com.
8. The gTLD name server only supports iterative queries and answers with the
authoritative name servers for the Second-Level Domain (SLD) example.com (a
referral).
9. The DNS Resolver selects one of the authoritative DNS servers for example.com
from the previous referral and sends it a query for the IP (the A RR) of
www.example.com.
10. The zone file for example.com defines www.example.com as a CNAME record (an
alias) for joe.example.com. The authoritative name server answers with the
www.example.com CNAME RR and, in this case, the A RR for joe.example.com,
which we will assume is 192.168.254.2.
11. The DNS Resolver sends the response joe.example.com=192.168.254.2
(together with the CNAME RR www=joe) to the original client stub-resolver.
12. The stub-resolver sends www.example.com=192.168.254.2 to the user’s browser.
13. The browser sends a request to 192.168.254.2 for the web page.
KEY-VALUE
显而易见,查询域名,返回IP,也可以查询IP,返回域名(Reverse Mapping)。nslookup和dig都是常用的命令。
nslookup yumianfeilong.com.
Non-authoritative answer:
Name: yumianfeilong.com
Address: 69.163.181.118nslookup 69.163.181.118
Non-authoritative answer:
118.181.163.69.in-addr.arpa name = apache2-bongo.yerevan.dreamhost.com.Authoritative answers can be found from:
181.163.69.in-addr.arpa nameserver = ns1.dreamhost.com.
181.163.69.in-addr.arpa nameserver = ns3.dreamhost.com.
181.163.69.in-addr.arpa nameserver = ns2.dreamhost.com.
ns1.dreamhost.com internet address = 66.33.206.206
ns2.dreamhost.com internet address = 208.96.10.221
ns3.dreamhost.com internet address = 66.33.216.216
