通过执行下面的命令可以清晰地理解DNS解析原理
dig @8.8.8.8 www.baidu.com +trace
执行结果
~ $ dig @8.8.8.8 www.baidu.com +trace
; <<>> DiG 9.10.6 <<>> @8.8.8.8 www.baidu.com +trace
; (1 server found)
;; global options: +cmd
. 18351 IN NS m.root-servers.net.
. 18351 IN NS b.root-servers.net.
. 18351 IN NS c.root-servers.net.
. 18351 IN NS d.root-servers.net.
. 18351 IN NS e.root-servers.net.
. 18351 IN NS f.root-servers.net.
. 18351 IN NS g.root-servers.net.
. 18351 IN NS h.root-servers.net.
. 18351 IN NS a.root-servers.net.
. 18351 IN NS i.root-servers.net.
. 18351 IN NS j.root-servers.net.
. 18351 IN NS k.root-servers.net.
. 18351 IN NS l.root-servers.net.
. 18351 IN RRSIG NS 8 0 518400 20190428050000 20190415040000 25266 . eyFh1C5rRPxNywPxwqTv2PK3Z1cX2/A91GYRjT/AHHW0emYcEL+nhCdI xwBUenAkolwtrnwBF88R5XATVgZmz6ms/9PMIWipFa/OkFwnGRzW4cCZ BDwIU9/Te26/33xu3pWCCJjSE2Y45/YFAbghDR8z7CgJEWeB8uG3734E9 hUSvptD3S9gWZSvrBHsJEvgXGI0e51REnbKQlKogYKtmHpjhx/Ldjs6n yko3oYxTStWt2Y0EPwH/ZIWLKlJlxnID2fjCOGyNBODyzsAi+SKQbhZh 1345lCutTIxurGseiajTBmgvryiRceDz7bL8SQ1GalyxDonfiJaGDD+a eXINQA==
;; Received 525 bytes from 8.8.8.8#53(8.8.8.8) in 6 ms
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
com. 86400 IN DS 30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CF C41A5766
com. 86400 IN RRSIG DS 8 1 86400 20190501050000 20190418040000 25266 . 205bedYkQO83dFd1ZuFMfRHSCFaaj4eXUcX8zWqQD3XVewsbLithhlGq tAIpLR94qn/J9tDUNQMyceQhv2mZgM5TD6wDNCUjEQQ5usV4q1VLh92/ CVpf+gICk7lqyWyUS8Unds9X27+lRZR4dP7yhPyY2RCDfurcI yLIFVMhQRrVSHc8QNrfSDBw9u0a2iZYz62MsCHum/6OWka1mSHYbq4PF 1k/qEO5QBc92Cj2IJdw6iZo9znLNZIPsjj5Vg0tGbnYFfCAvrUNqfZEl QsD2Tqobx1IdaOlXZVnYoRiuse8geB5nOJz9LM9QiiaZAhV4mYlpt51c G/uPdw==
;; Received 1173 bytes from 2001:7fd::1#53(k.root-servers.net) in 4 ms
baidu.com. 172800 IN NS ns2.baidu.com.
baidu.com. 172800 IN NS ns3.baidu.com.
baidu.com. 172800 IN NS ns4.baidu.com.
baidu.com. 172800 IN NS ns1.baidu.com.
baidu.com. 172800 IN NS ns7.baidu.com.
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN NSEC3 1 1 0 - CK0Q1GIN43N1ARRC9OS1H5M9A NS SOA RRSIG DNSKEY NSEC3PARAM
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN RRSIG NSEC3 8 2 86400 20190425044519 20190418033519 3800 com. X4RMuixFEM0vXh+R/EdM+DwtW23FcdQyBtM2ZOwALeOlO4pa+mDQm9L6 mmfIFmvzn3o4sMkXTebkKDr10XCFlroyVyxpuD/kIw6K54IayvICoH9y 7Lu2lbpH8j3VCmbCEnNcZyF8wywnXzJSBdHWfh1ZYY+YldbOQ70b2/US iBA=
HPVV2B5N85O7HJJRB7690IB5UVF9O9UA.com. 86400 IN NSEC3 1 1 0 - HPVVN3Q5E5GOQP2QFE2LEM4SVB9C0SJ6 NS DS RRSIG
HPVV2B5N85O7HJJRB7690IB5UVFA.com. 86400 IN RRSIG NSEC3 8 2 86400 20190423050521 20190416035521 3800 com. eE9OkujwohzKmUQBKRIHjn+b1lX2oiI9nl27uPCcJwr0ZkOOy 0J4c/1OyG2TaLkZaF+PZ9YfWYBDnKe3Ewv0CnfunwzM6hYHnGCKmUAyn 3N6OI+MbqaLKdgaEZ4K25UDDUeJgJuiTf7WeVU/CI0mQvpDAPCJ7E6Lg z3w=
;; Received 697 bytes from 192.67.89.30#53(j.gtld-servers.net) in 106 ms
www.baidu.com. 1200 IN CNAME www.a.shifen.com.
a.shifen.com. 1200 IN NS ns2.a.shifen.com.
a.shifen.com. 1200 IN NS ns3.a.shifen.com.
a.shifen.com. 1200 IN NS ns1.a.shifen.com.
a.shifen.com. 1200 IN NS ns4.a.shifen.com.
a.shifen.com. 1200 IN NS ns5.a.shifen.com.
;; Received 239 bytes from 180.65.78.92#53(ns7.baidu.com) in 81 ms
~ $
可以看到,解析
- 查询全球13台根域名服务器
- 然后查询com的顶级域名服务器
- 然后是一级,二级等服务器,完成解析过程