Some basics of DNS, and the process of DNS conversion domain name

DNS (Domain Name System), the main function is to convert the domain name to IP. This article mainly explains some basic knowledge of DNS and the process of DNS conversion domain name.

What is DNS

dig command

The vast majority of network communication is based on the TCP/IP protocol, and the basis of the TCP/IP protocol is IP, so the communication between computers in the network is based on IP instead of the domain name we enter in the browser. DNS is the Domain Name System throughout, and its function is actually very simple, that is, to translate the input domain name into the corresponding IP.

Using the dig command can help us understand what DNS is doing.

dig command

  1. Query parameters and some statistics.

  1. The information you want to query, for example, this time you are looking for the A record (actual IP address) of ditu.amap.com .

  1. The reply information of the DNS server, after jumping through various CNAME records, finds the final A record, 203.119.214.249, which is what we want the DNS service to do for us: domain name --> IP.

  1. Some transmission information, the DNS server used by this machine, query time consumption, message size, etc.

basic concept

DNS record type

The correspondence between domain name and IP is called "record". According to usage scenarios, "records" can be divided into different types (types), as we have seen above, there are A records and CNAME records.

Commonly used record types are as follows:

type

name

illustrate

A

Address record (Address)

Returns the IP address pointed to by the domain name

CNAME

Address record (Address)

Return another domain name, that is, the currently queried domain name is a jump to another domain name

NS

Name Server Records (Name Server)

Returns the address of the server that saves the information of the next-level domain name. This record can only be set as a domain name, not an IP address. In order to ensure the reliability of the service, NS generally has at least 2 entries

MX

Mail records (Mail eXchange)

Returns the address of the server receiving the email

PTR

Reverse query record (Pointer Record)

Only used to look up domain names from IP addresses

The composition of the domain name

域名的组成结构为:主机名.次级域名.顶级域名.根域名

在第一个图中可以看到每个域名跟我们印象的域名不大相同,在每个域名的后面都会跟一个“.”。这是因为实际上所有的域名后面都有一个“.”,而这个点其实是“.root”的缩写代表的是“根域名”。而根域名对所有的域名都相同,所以在平时的使用中可以省略,而在域名解析中却是至关重要。

根域名的下一级,叫做"顶级域名"(top-level domain,缩写为 TLD),比如 .com、.cn;再下一级叫做"次级域名"(second-level domain,缩写为 SLD),比如 ditu.amap.com 里面的 .amap,这一级域名是用户可以注册的;再下一级是主机名(host),比如 ditu.amap.com 里面的 ditu,又称为"三级域名",这是用户在自己的域里面为服务器分配的名称,是用户可以任意分配的。

ditu(三级域名).amap(次级域名).com(顶级域名).root(根域名)

查询过程

DNS 服务是根据域名层级,分级进行查询,从根域名开始,依次查询每一级域名的 NS 记录,直到查到最终的 IP 地址。

  1. 从"根域名服务器"查到"顶级域名服务器"的 NS 记录和 A 记录(IP 地址)

  1. 从"顶级域名服务器"查到"次级域名服务器"的 NS 记录和 A 记录(IP 地址)

  1. 从"次级域名服务器"查出"主机名"的 IP 地址

根域名服务器

我们可以看到查找过程是从“根域名服务器”开始,那么从哪里知道“根域名服务器”呢?其实“根域名服务器"的 NS 记录和 IP 地址一般是不会变化的,所以内置在 DNS 服务器里面,世界上一共有十三组根域名服务器,从 a.root-servers.net 一直到 m.root-servers.net

DNS 解析过程

DNS解析

DNS解析

有了以上的知识后,借助 dig 命令 +trace 可以看到 DNS 整体的分级查询过程,其中黄色框中是逐级要获取的域名地址,红色框中是从哪里获取的结果,我们可以看到首先获取的是a-m的根域名服务地址,再逐级获取 .com-->amap.com-->ditu.amap.com,最终我们可以得到一条名为zone.wagbridge.gaode.com. 的 CNAME 记录。

我们可以使用 dig ns amap.com 来查看每级的 NS 记录信息,同样可以印证上图里面 ditu.amap.com 的数据返回地址。

dig ns

Q&A

为什么要有 CNAME

这对于需要在同一个IP地址上运行多个服务的情况来说非常方便。若要同时运行文件传输服务和 Web 服务,则可以把 ftp.example.comwww.example.com 都指向 DNS 记录 example.com,而后者则指向 IP 地址的 A 记录。如此一来,若服务器 IP 地址改变,则只需修改 example.com 的 A 记录即可。

DNS 解析中的 DS,RRSIG 是什么

DNS 的原始设计不包含任何安全细节,域名系统安全扩展(DNSSEC)尝试在其中添加安全性,同时仍保持向后兼容性。DNSSEC 旨在保护应用程序,免受伪造或不当操纵的 DNS 数据所造成的影响(例如域名服务器缓存污染的数据)。来自 DNSSEC 保护区的所有答案都经过数字签名。通过检验数字签名,DNS 解析器可以核查信息是否与区域所有者发布的信息相同(未修改和完整),并确系实际负责的 DNS 服务器所提供。

新增三种资源记录类型:RRSIG (Resource Record Signature)、DNSKEY (DNS Public Key)、DS (Delegation Signer)。

DNS 原理入门
维基百科
台湾大学

Guess you like

Origin blog.csdn.net/m0_67511426/article/details/128672008
Recommended