1. DNS是什么?
DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去+·记住能够被机器直接读取的IP数串。
通过主机名,最终得到该主机名对应的IP地址的过程叫做域名解析(或主机名解析)。
DNS协议运行在UDP协议之上,使用端口号53。
访问网站的实质就是解析其域名得到IP地址,再转向其网站。
就是将浏览器中的 www.baidu.com 通过DNS解析得到IP地址:183.232.231.172
2. DNS的作用
- A记录,即Address记录: www.baidu.com --> 183.232.231.172
- CNAME 起别名,常备CDN服务上应用
- MX解析记录 [email protected] 搭建邮件服务
- PTR 反向解析,1.1.1.1 -->www.domain.com 邮件服务
A记录的解析过程:
浏览器--> www.etiantian.org --> 网站服务器的ip地址 --> ip地址对应的网站服务器
3. DNS的解析原理
原理步骤:
- 系统首先会查找本地的DNS缓存和hosts文件信息,确认其中是否有与 域名www.baidu.com所对应的IP地址。
如果有,就直接访问这个IP地址所对应的www.baidu.com 域名服务器.
# macbook的hosts文件信息 192:etc zoe$ cat /etc/hosts ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 139.224.179.40 dcba 10.86.212.19 pi01 10.86.212.56 pi02 # 虚拟机上linux的hosts信息 [[email protected] ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
- 如果没有找到,那么,系统将会把浏览器的解析请求发送给 本地主机所指定的DNS服务器,称为LDNS。
如果LDNS服务器中有域名www.baidu.com 所对应的IP地址,则返回给客户端的浏览器,如果没有,则继续请求其他DNS服务器。
- LDNS服务器会从DNS系统的根(.)开始请求对域名 www.baidu.com 的解析。根DNS服务器全球只有13台,根域名服务器是没有域名 www.baidu.com 解析记录的。但是它会有域名 www.baidu.com 所对应的顶级域 .com的解析记录,因此直接把顶级域 .com所对应的DNS地址返回给LDNS服务器。
- LDNS服务器获取到顶级域.com对应的DNS服务器地址后,就会去.com服务器请求对www.baidu.com 域名的解析。在顶级域名服务器也不会有 www.baidu.com 的解析记录。但是它具有www.baidu.com 的父级域名的解析记录,即baidu.com。 因此顶级域名 .com服务器又会把 baidu.com 所对应的DNS服务器的IP地址返回给LDNS。
- LDNS服务器收到baidu.com 所对应的IP地址后,就会去baidu.com域名服务器请求对 www.baidu.com 的域名解析。Baidu.com 域名对应的DNS服务器是该域名的授权DNS服务器。这个DNS服务器就是企业购买域名时用于管理解析的服务器。
- baidu.com 域名DNS服务器会把 www.baidu.com 域名所对应的IP地址给解析出来,然后发送给LDNS。
- LDNS把解析出来的结果,www.baidu.com 所对应的IP地址发送给客户端的浏览器。并且LDNS也会将其域名和对应的地址缓存到cache中。
- 客户端浏览器收到后,也会将其域名以及对应的IP地址缓存到DNS缓存和hosts文件中。
知识梳理:
DNS数据库的结构如下图所示,就像一棵倒挂着的树。
它的顶点也是根(.)
全球总共有 13台 根DNS服务器。
顶级域名 org, com, net, me, cc,
一级域名:baidu, sina, google, alibaba, taobao
DNS域名解析命令:
- dig
- nslookup
- host
- ping
dig命令解析dns
192:etc zoe$ 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 . 211565 IN NS a.root-servers.net. . 211565 IN NS b.root-servers.net. . 211565 IN NS c.root-servers.net. . 211565 IN NS d.root-servers.net. . 211565 IN NS e.root-servers.net. . 211565 IN NS f.root-servers.net. . 211565 IN NS g.root-servers.net. . 211565 IN NS h.root-servers.net. . 211565 IN NS i.root-servers.net. . 211565 IN NS j.root-servers.net. . 211565 IN NS k.root-servers.net. . 211565 IN NS l.root-servers.net. . 211565 IN NS m.root-servers.net. . 211565 IN RRSIG NS 8 0 518400 20191005050000 20190922040000 59944 . kFUBbJE9raFU30U6hkdXdjkSmMeokgUl7GMZokb1cX7XAIXMuJSlqtxP 1zouEX6o/49O4pwIJL8DlCOpAJ+Fk84xbY+0i32BAlkTPBd6KwqU7Fra UaKe1a6ylMFg6Ov4kaTpL/Y4njrobc3N+FL0pBZX6/hH5ltNVyutpiDt 3ZXWjCqHy8tJcd/MV4zIbvlLZ52cLCufzIxAVQrbryg4tpkkUrb+BiR8 VYuBG/y+RToCZRgmf3vTX06G3RKADwcOBiBj0jt/RQMCZjC4BGdTD/H9 bwyaKEXRjCi53AspEDfI7hF+uPHB+Fd+lRa9rjGi5jyf+e56dKg6IKsp 1VqSSQ== ;; Received 525 bytes from 8.8.8.8#53(8.8.8.8) in 200 ms com. 172800 IN NS l.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 a.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 m.gtld-servers.net. com. 86400 IN DS 30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CF C41A5766 com. 86400 IN RRSIG DS 8 1 86400 20191006050000 20190923040000 59944 . Pe9CAXBj4SVoH+viy4eJMGSCOQZPWyPH6sOoNRE1O7ScsqdNPqaLBLYt DRXEAmwC+wKiqiLbwTcIzQbraifFDOeftMXeA4Zx23AXuuU2w84PWe1h 0TqgQwGyZnEIhbEj9OryhTvc/LcC1Govyk6cgDhJhxVNy3A2fhDU5eOp KcbxEp5VeLMtilQMdrjPSMQAy8RNDgoHvd5YBmpjUlGquvpASHEItZlZ hT6dWQYSqroI4ruyt6xCvrcKCma2nyR78FcZZLdg2jTJFaBsOaAsnI0V nfrWXsD09S4EvTHq+SIEIHyvJgC2+HKScUUlJgXTDAdd0zLxlQqW4fcn z5xhyQ== ;; Received 1173 bytes from 192.5.5.241#53(f.root-servers.net) in 41 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 - CK0Q1GIN43N1ARRC9OSM6QPQR81H5M9A NS SOA RRSIG DNSKEY NSEC3PARAM CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN RRSIG NSEC3 8 2 86400 20190928044441 20190921033441 17708 com. G131mLtsBTVuH1wpOFbRs0/voaY+V7rxVJHc9XWhCelqZkbFiB6tVxKw oqpWdiXL+p4V40G3Koo8Y7y/Qd2M+hV4edC0nal1RrNt97hkRLQAcTJ/ wHZcMl84JbDtZT44UY1iHWv4GUxlxyaQiew/YceADjSzNtqG8mU1zNhC P1g= HPVV2B5N85O7HJJRB7690IB5UVF9O9UA.com. 86400 IN NSEC3 1 1 0 - HPVVN3Q5E5GOQP2QFE2LEM4SVB9C0SJ6 NS DS RRSIG HPVV2B5N85O7HJJRB7690IB5UVF9O9UA.com. 86400 IN RRSIG NSEC3 8 2 86400 20190930045238 20190923034238 17708 com. k5LZWJ8Oa5v6NqVOZ9PUeDx0vdwV6gFSH0EZp9rFHr9GeAYPOnr0ucQX XogUAJweh+CvXYMqFa3s3ZQUsqbRv2O5XTjKuZDrOzBSPooK3csZ1tJy q5HdJczJeMVTdHsbaVcO2Kt1Iwl+5Obl8UCt60ZfyTQoegAI+dtQdPNa ADA= ;; Received 697 bytes from 192.41.162.30#53(l.gtld-servers.net) in 266 ms www.baidu.com. 1200 IN CNAME www.a.shifen.com. a.shifen.com. 1200 IN NS ns3.a.shifen.com. a.shifen.com. 1200 IN NS ns4.a.shifen.com. a.shifen.com. 1200 IN NS ns5.a.shifen.com. a.shifen.com. 1200 IN NS ns2.a.shifen.com. a.shifen.com. 1200 IN NS ns1.a.shifen.com. ;; Received 239 bytes from 14.215.178.80#53(ns4.baidu.com) in 42 ms 192:etc zoe$ 192:etc zoe$ 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 . 197496 IN NS a.root-servers.net. . 197496 IN NS b.root-servers.net. . 197496 IN NS c.root-servers.net. . 197496 IN NS d.root-servers.net. . 197496 IN NS e.root-servers.net. . 197496 IN NS f.root-servers.net. . 197496 IN NS g.root-servers.net. . 197496 IN NS h.root-servers.net. . 197496 IN NS i.root-servers.net. . 197496 IN NS j.root-servers.net. . 197496 IN NS k.root-servers.net. . 197496 IN NS l.root-servers.net. . 197496 IN NS m.root-servers.net. . 197496 IN RRSIG NS 8 0 518400 20191005050000 20190922040000 59944 . kFUBbJE9raFU30U6hkdXdjkSmMeokgUl7GMZokb1cX7XAIXMuJSlqtxP 1zouEX6o/49O4pwIJL8DlCOpAJ+Fk84xbY+0i32BAlkTPBd6KwqU7Fra UaKe1a6ylMFg6Ov4kaTpL/Y4njrobc3N+FL0pBZX6/hH5ltNVyutpiDt 3ZXWjCqHy8tJcd/MV4zIbvlLZ52cLCufzIxAVQrbryg4tpkkUrb+BiR8 VYuBG/y+RToCZRgmf3vTX06G3RKADwcOBiBj0jt/RQMCZjC4BGdTD/H9 bwyaKEXRjCi53AspEDfI7hF+uPHB+Fd+lRa9rjGi5jyf+e56dKg6IKsp 1VqSSQ== ;; Received 525 bytes from 8.8.8.8#53(8.8.8.8) in 265 ms com. 172800 IN NS l.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 a.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 m.gtld-servers.net. com. 86400 IN DS 30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CF C41A5766 com. 86400 IN RRSIG DS 8 1 86400 20191006050000 20190923040000 59944 . Pe9CAXBj4SVoH+viy4eJMGSCOQZPWyPH6sOoNRE1O7ScsqdNPqaLBLYt DRXEAmwC+wKiqiLbwTcIzQbraifFDOeftMXeA4Zx23AXuuU2w84PWe1h 0TqgQwGyZnEIhbEj9OryhTvc/LcC1Govyk6cgDhJhxVNy3A2fhDU5eOp KcbxEp5VeLMtilQMdrjPSMQAy8RNDgoHvd5YBmpjUlGquvpASHEItZlZ hT6dWQYSqroI4ruyt6xCvrcKCma2nyR78FcZZLdg2jTJFaBsOaAsnI0V nfrWXsD09S4EvTHq+SIEIHyvJgC2+HKScUUlJgXTDAdd0zLxlQqW4fcn z5xhyQ== ;; Received 1173 bytes from 192.203.230.10#53(e.root-servers.net) in 41 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 - CK0Q1GIN43N1ARRC9OSM6QPQR81H5M9A NS SOA RRSIG DNSKEY NSEC3PARAM CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN RRSIG NSEC3 8 2 86400 20190928044441 20190921033441 17708 com. G131mLtsBTVuH1wpOFbRs0/voaY+V7rxVJHc9XWhCelqZkbFiB6tVxKw oqpWdiXL+p4V40G3Koo8Y7y/Qd2M+hV4edC0nal1RrNt97hkRLQAcTJ/ wHZcMl84JbDtZT44UY1iHWv4GUxlxyaQiew/YceADjSzNtqG8mU1zNhC P1g= HPVV2B5N85O7HJJRB7690IB5UVF9O9UA.com. 86400 IN NSEC3 1 1 0 - HPVVN3Q5E5GOQP2QFE2LEM4SVB9C0SJ6 NS DS RRSIG HPVV2B5N85O7HJJRB7690IB5UVF9O9UA.com. 86400 IN RRSIG NSEC3 8 2 86400 20190930045238 20190923034238 17708 com. k5LZWJ8Oa5v6NqVOZ9PUeDx0vdwV6gFSH0EZp9rFHr9GeAYPOnr0ucQX XogUAJweh+CvXYMqFa3s3ZQUsqbRv2O5XTjKuZDrOzBSPooK3csZ1tJy q5HdJczJeMVTdHsbaVcO2Kt1Iwl+5Obl8UCt60ZfyTQoegAI+dtQdPNa ADA= ;; Received 697 bytes from 192.43.172.30#53(i.gtld-servers.net) in 192 ms www.baidu.com. 1200 IN CNAME www.a.shifen.com. a.shifen.com. 1200 IN NS ns4.a.shifen.com. a.shifen.com. 1200 IN NS ns1.a.shifen.com. a.shifen.com. 1200 IN NS ns3.a.shifen.com. a.shifen.com. 1200 IN NS ns5.a.shifen.com. a.shifen.com. 1200 IN NS ns2.a.shifen.com. ;; Received 239 bytes from 14.215.178.80#53(ns4.baidu.com) in 43 ms
nslookup域名解析
[[email protected] ~]# nslookup > baidu.com Server: 192.168.1.1 Address: 192.168.1.1#53 Non-authoritative answer: Name: baidu.com Address: 39.156.69.79 Name: baidu.com Address: 220.181.38.148
host域名
[[email protected] ~]# host www.baidu.com www.baidu.com is an alias for www.a.shifen.com. www.a.shifen.com has address 183.232.231.174 www.a.shifen.com has address 183.232.231.172
ping 域名返回地址
[[email protected] ~]# ping www.baidu.com PING www.baidu.com (183.232.231.174) 56(84) bytes of data. 64 bytes from 183.232.231.174: icmp_seq=1 ttl=55 time=43.8 ms 64 bytes from 183.232.231.174: icmp_seq=2 ttl=55 time=44.2 ms
原文地址:https://www.cnblogs.com/zoe233/p/11823857.html
时间: 2024-11-02 13:05:19