大家都知道 DNS (Domain Name System, 域名系统), 是一个域名和 IP 地址映射系统. 通过 DNS 我们可以根据比较容易记住的域名而不是数字 IP 地址来访问网络资源. 本文主要使用 dig (ubuntu 上可以通过 sudo apt install dnsutils 安装) 工具来了解 DNS 的各方面.
0x01 CNAME 和 A 记录
在 DNS 中, A 记录值表示的是真正的 IP 地址, 而 CNAME 相当于域名的别名. 我们来看一个例子, 新浪的 DNS 解析:
; <<>> DiG 9.10.3-P4-Ubuntu <<>> www.sina.com.cn +trace ;; global options: +cmd . 3600 IN NS d.root-servers.net. . 3600 IN NS e.root-servers.net. . 3600 IN NS f.root-servers.net. . 3600 IN NS g.root-servers.net. . 3600 IN NS h.root-servers.net. . 3600 IN NS i.root-servers.net. . 3600 IN NS j.root-servers.net. . 3600 IN NS k.root-servers.net. . 3600 IN NS l.root-servers.net. . 3600 IN NS m.root-servers.net. . 3600 IN NS a.root-servers.net. . 3600 IN NS b.root-servers.net. . 3600 IN NS c.root-servers.net. ;; Received 1771 bytes from 192.168.1.6#53(192.168.1.6) in 0 ms
cn. 172800 IN NS b.dns.cn. cn. 172800 IN NS ns.cernet.net. cn. 172800 IN NS c.dns.cn. cn. 172800 IN NS d.dns.cn. cn. 172800 IN NS a.dns.cn. cn. 172800 IN NS g.dns.cn. cn. 172800 IN NS f.dns.cn. cn. 172800 IN NS e.dns.cn. cn. 86400 IN DS 41470 8 2 3623FB6E3B1F69C6855DA1E48D3A38236DD2EDF0380FB018FF538650 EAC2C4DD cn. 86400 IN DS 57724 8 2 5D0423633EB24A499BE78AA22D1C0C9BA36218FF49FD95A4CDF1A4AD 97C67044 cn. 86400 IN RRSIG DS 8 1 86400 20180313050000 20180228040000 41824 . GbRg9UYKus5nqvJxCKVZTaX5j2WYaF2c3jH5XOEPzqgcGp23+U941ZHz nKAXTv8oJq2+dJiRuVnwAD7c+Ge8MBJbd+tpw0jcQ3zs3SiocVhWgF3/ Bjig8ouJsuKukEuF89tx+oqbYjRrau9PFNJBoN2zlVZP1JQYTukYaGeY aK91OtgRuC1yVVQqNstLhU+YWyi7gNKOd31SMSpyvUZDIf+8wQrR6j9y dUb7zex8dk+XFS9/NqOXi6kRQxOPdflXXGieNZRVAnHfKdgO3LsXYmsD 92CY9G7cwj9XShFdYq7GLSirh3c9LvUR4E0VKk6qcr3usgKbmDPumyAv aN+ZwA== ;; Received 754 bytes from 192.33.4.12#53(c.root-servers.net) in 173 ms
sina.com.cn. 86400 IN NS ns3.sina.com.cn. sina.com.cn. 86400 IN NS ns2.sina.com.cn. sina.com.cn. 86400 IN NS ns1.sina.com.cn. sina.com.cn. 86400 IN NS ns4.sina.com.cn. GICE14DNTMDN31G43AUGVRKTKALVB8QC.com.cn. 21600 IN NSEC3 1 1 10 AEF123AB HIO2MHL5BSKBHFFRA5I1J58SU91CDLLA NS SOA RRSIG DNSKEY NSEC3PARAM GICE14DNTMDN31G43AUGVRKTKALVB8QC.com.cn. 21600 IN RRSIG NSEC3 8 3 21600 20180318092826 20180216084403 48018 com.cn. iuUIwe/vd4QLsTo8behQVf8ZPWaU9JsP+gxrUHop+oybuZH+II+kvOBW wTfGHap/n3C7iSevN80Wa2eFeH0QBWif2A30+zfg9hCzVjEEUDulmc1a 4+ltDbv4UZVJpBPRU7n2AgW4UMK/q0vyWqV6oKwmIygj58fhrMkqcrpR CpU= T1MQAIVAIU5JVK5ON55K8AOCE62H72MI.com.cn. 21600 IN NSEC3 1 1 10 AEF123AB UQROTQK62NOIM5U43DMF7AMC8JJFRM7T NS DS RRSIG T1MQAIVAIU5JVK5ON55K8AOCE62H72MI.com.cn. 21600 IN RRSIG NSEC3 8 3 21600 20180311113832 20180209104700 48018 com.cn. I1zxGBgSFJfq5GCrwlukCCkWNeQRcJJu9ydX5OgoH0mdYwVVLGoB2y1D htn8lGc4MMfdbY+zTdlnvYvBHdtFSS2+2eq+ficKzzZQ2CVtDrFm91Eo 0MK+BavvLcE5pkRpIfpI9FIIMrlNaj9cOBwWNR2g1yXfSYWSr5NUFKQG voE= ;; Received 679 bytes from 203.119.25.1#53(a.dns.cn) in 33 ms
www.sina.com.cn. 0 IN CNAME spool.grid.sinaedge.com. ;; Received 81 bytes from 61.172.201.254#53(ns2.sina.com.cn) in 5 ms