网络知识 - DNS

网络知识 - DNS

DNS 服务器 - 层级

Screen Shot 2020-12-29 at 4.31.32 PM

  • 根域名服务器(Root DNS Server)
  • 顶级域名服务器(Top-level DNS Server),每个顶级域名服务器管理各自下属
  • 次级域名,如 baidu.com 里的 baidu,这个是用户可以进行注册购买的
  • 主机域名,比如 baike.baidu.com 里的baike,这个是用户可分配的

DNS 查询

Screen Shot 2020-12-29 at 4.32.14 PM
  • 检查自己本地的 hosts 文件是否有这个网址映射关系,如果有就先调用这个 IP 地址映射完成域名解析。
  • 查找本地 DNS 解析器缓存是否有这个网址映射关系,如果有直接返回,完成域名解析。
  • 如果 hosts 与本地 DNS 解析器缓存都没有相应的网址映射关系,首先会找 TCP/IP 参数中设置的首选 DNS 服务器,在此我们叫它本地 DNS 服务器,此服务器收到查询时,如果要查询的域名,包含在本地配置区域资源中,则返回解析结果给客户机,完成域名解析,此解析具有权威性。
  • 转发: 本地 DNS 就把请求发至 “根 DNS 服务器”,“根 DNS 服务器”收到请求后会判断这个域名(.com)是谁来授权管理,并会返回一个负责该顶级域名服务器的一个 IP。本地 DNS 服务器收到 IP 信息后,将会联系负责 .com 域的这台服务器。这台负责 .com 域的服务器收到请求后,如果自己无法解析,它就会找一个管理 .com 域的下一级 DNS 服务器地址 给本地 DNS 服务器

总结: 从"根域名服务器"查到"顶级域名服务器"的NS记录和A记录(IP地址),从"顶级域名服务器"查到"次级域名服务器"的NS记录和A记录(IP地址),从"次级域名服务器"查出"主机名"的IP地址

DNS相关记录

A:地址记录(Address),返回域名指向的IP地址

CNAME (alias):规范名称记录(Canonical Name),返回另一个域名,即当前查询的域名是另一个域名的跳转

NS:域名服务器记录(Name Server),返回保存下一级域名信息的服务器地址。该记录只能设置为域名,不能设置为IP地址

PTR:逆向查询记录(Pointer Record),只用于从IP地址查询域名

CName Vs A Record

The A record maps a name to one or more IP addresses when the IP are known and stable.The CNAME record maps a name to another name. It should only be used when there are no other records on that name.

https://support.dnsimple.com/articles/differences-a-cname-records/

eg

blog.dnsimple.com.      CNAME   aetrion.github.io.
aetrion.github.io. CNAME github.map.fastly.net.
github.map.fastly.net. A 185.31.17.133

We use GitHub Pages, and we set blog.dnsimple.com as a CNAME of aetrion.github.io, which is a CNAME of github.map.fastly.net, which is an A record pointing to 185.31.17.133. This means blog.dnsimple.com resolves to 185.31.17.133.

命令行工具

nslookup

nslookup [域名] [dns服务器]

Screen Shot 2020-12-29 at 4.44.20 PM

dig (推荐)

dig [server] [name] [type]

// 不指定DNS server
dig google.com
// 指定DNS server
dig @8.8.8.8 google.com
// 指定记录类型
dig cname @8.8.8.8 google.com

// not verbose
dig @8.8.8.8 google.com +short

// trace option : lists each different server the query goes through to its final destination
dig @8.8.8.8 google.com +trace

// reverse DNS lookup (根据IP 查域名)
dig –x [ip]

whois

查看域名的注册情况