当前位置:网站首页>Detailed explanation of DNS query principle
Detailed explanation of DNS query principle
2022-08-05 08:09:00 【hebiwen95】
通过 DNS 查询,得到域名的 IP 地址,才能访问网站.
那么,DNS Exactly how the query is done?This article uses examples,Details the steps behind.

一、DNS 服务器
域名对应的 IP 地址,都保存在 DNS 服务器.
我们输入域名,The browser will be in the background,自动向 DNS 服务器发出请求,获取对应的 IP 地址.这就是 DNS 查询.

举例来说,我输入 es6.ruanyifeng.com 这个域名,The browser is going to DNS 服务器查询,它的 IP 地址是什么,然后向该 IP 发出访问请求.
There are many public ones available online DNS 服务器,这篇文章选择 Cloudflare 公司提供的 1.1.1.1 进行演示.

二、dig 命令
命令行工具 dig 可以跟 DNS 服务器互动,We will use it to demonstrate DNS 查询.如果你还没有安装,You can search for the installation method,在 Linux system is very easy.
Its query syntax is as follows(美元符号$是命令行提示符).
$ dig @[DNS 服务器] [域名]向 1.1.1.1 查询域名,就执行下面的命令.
$ dig @1.1.1.1 es6.ruanyifeng.com正常情况下,It will output a whole bunch of stuff.

在其中找到 ANSWER SECTION 这个部分,It gives the answer to the query,域名对应的 IP 地址是 104.198.14.52.
三、The tree structure of domain names
你可能会问,难道 DNS 服务器(比如 1.1.1.1)Save all the domain names in the world(包括二级域名、三级域名)的 IP 地址?
当然不是.DNS 是一个分布式系统,1.1.1.1 Just the user query entry,It also needs to go to the other DNS 服务器查询,to obtain the final IP 地址.
要说清楚 DNS 完整的查询过程,就必须了解 A domain name is a tree structure.
The top-level domain name is the root domain name(root),Then there are the top-level domains(top-level domain,简写 TLD),Then there is the first-level domain name、二级域名、三级域名.

(1)根域名
The starting point of all domain names is the root domain name,It writes a dot.,at the end of the domain name.Because this part is the same for all domains,So it is omitted not to write,比如example.com等同于example.com.(One more point at the end).
你可以试试,Add a dot at the end of any domain name,Browsers can interpret it normally.
(2)顶级域名
The level below the root domain name is the top-level domain name.它分成两种:通用顶级域名(gTLD,比如 .com 和 .net)and country-specific top-level domains(ccTLD,比如 .cn 和 .us).
Top-level domains are managed by the International Domain Name Authority ICANN 控制,It is entrusted to the management of commercial companies gTLD,Entrust countries to manage their own country-specific domain names.
(3)一级域名
A first-level domain is where you are below a top-level domain,自己注册的域名.比如,ruanyifeng.comThat's me at the top level domain.com下面注册的.
(4)二级域名
二级域名是一级域名的子域名,It is set by the domain owner,No permission required.比如,es6 就是 ruanyifeng.com 的二级域名.
四、Domain name level-by-level query
The significance of this tree structure is that,Only the upper-level domain name,Only know the next level domain name IP 地址,Need to query step by step.
每一级域名都有自己的 DNS 服务器,Store subordinate domain names IP 地址.
所以,If you want to query the second-level domain name es6.ruanyifeng.com 的 IP 地址,需要三个步骤.
第一步,查询根域名服务器,Get top-level domain name servers
.com(又称 TLD 服务器)的 IP 地址.第二步,查询 TLD 服务器
.com,Obtain a first-level domain name serverruanyifeng.com的 IP 地址.第三步,Query the first-level domain name server
ruanyifeng.com,Get a second-level domain namees6的 IP 地址.
The three steps are shown in turn below.
五、根域名服务器
The root name servers are all over the world13台(All are server clusters).their domain names and IP 地址如下.

根域名服务器的 IP 地址是不变的,integrated into the operating system.
The operating system will choose one of them,查询 TLD 服务器的 IP 地址.
$ dig @192.33.4.12 es6.ruanyifeng.com上面示例中,我们选择192.33.4.12,Issue a query to it,询问es6.ruanyifeng.com的 TLD 服务器的 IP 地址.
dig The output of the command is as follows.

Because it can't give es6.ruanyifeng.com 的 IP 地址,所以输出结果中没有 ANSWER SECTION,只有一个 AUTHORITY SECTION,给出了com.的13台 TLD 服务器的域名.
下面还有一个 ADDITIONAL SECTION,给出了这13台 TLD 服务器的 IP 地址(包含 IPv4 和 IPv6 两个地址).
六、TLD 服务器
有了 TLD 服务器的 IP 地址以后,We choose another one and then query.
$ dig @192.41.162.30 es6.ruanyifeng.com上面示例中,192.41.162.30 It's any one you choose .com 的 TLD 服务器,We ask it es6.ruanyifeng.com 的 IP 地址.
返回结果如下.

It still doesn't ANSWER SECTION 的部分,只有 AUTHORITY SECTION,A first-level domain name is given ruanyifeng.com 的两台 DNS 服务器.
下面的 ADDITIONAL SECTION Just these two DNS 服务器对应的 IP 地址.
七、一级域名的 DNS 服务器
第三步,Then to the first-level domain name DNS The server queries the second-level domain name IP 地址.
$ dig @172.64.32.123 es6.ruanyifeng.com返回结果如下.

这次终于有了 ANSWER SECTION,Got the final second-level domain name IP 地址.
至此,three steps DNS 查询全部完成.
八、DNS 服务器的种类
总结一下,There are four types of servers mentioned above.
•1.1.1.1•根域名服务器•TLD 服务器•一级域名服务器
它们都属于 DNS 服务器,are used to accept DNS 查询.但是作用不一样,属于不同的类别.
8.1 递归 DNS 服务器
The latter three servers are only used to query the next-level domain name IP 地址,而 1.1.1.1 The step-by-step query process is automated,It is convenient for users to get the results at one time,所以它称为递归 DNS 服务器(recursive DNS server),That is, recursive queries can be performed automatically.
我们平常说的 DNS 服务器,Usually refers to recursion DNS 服务器.它把 DNS Queries are automated,Just ask it about it.
It has cache inside,The results of previous queries can be saved,Next time someone asks,Just return the result in the cache directly.So it can speed up the query,lighten the source DNS 服务器的负担.
8.2 权威 DNS 服务器
The official name of the first-level name server is called 权威域名服务器(Authoritative Name Server).
“权威”means domain name IP The address is given by it,Unlike recursive servers that can't make up their own minds.After we buy the domain name,设置 DNS The server is the authoritative server that is setting the domain name.
8.3 四种 DNS 服务器
综上所述,DNS There are four types of servers:
•根域名服务器•TLD 服务器•权威域名服务器•Recursive nameservers
它们的关系如下图.

知道了 DNS 查询的原理,完全可以自己写一个 DNS recursive server,这是不难的.网上有很多参考资料,有兴趣的话,大家可以试试看.

边栏推荐
- TensorFlow installation steps
- JS实现从照片中裁切自已的肖像
- [Untitled] Long-term recruitment of hardware engineers-Shenzhen Baoan
- [转帖]嫁人一定要嫁工资至少比你高3571.4元的男士
- Redis实现分布式锁-原理-问题详解
- 随机码的生成
- 基于 Docker 快速使用远程(云)数据库
- 基于多块信息提取和马氏距离的k近邻故障监测
- Redis cache and existing problems--cache penetration, cache avalanche, cache breakdown and solutions
- php向mysql写入数据失败
猜你喜欢

SVG星球大战样式Toggle切换开关按钮

Fiddler工具讲解

微信 小程序 之PC端 不支持 wx.previewMedia 方法 故用自定义轮播图进行 模拟照片视频的播放

D2--FPGA SPI interface communication2022-08-03

利用Jenkins的持续集成
![[Structural Internal Power Cultivation] The Mystery of Enumeration and Union (3)](/img/39/d20f45ccc86ebc4e5aebc8e4d0115f.png)
[Structural Internal Power Cultivation] The Mystery of Enumeration and Union (3)

吴恩达深度学习deeplearning.ai——第一门课:神经网络与深度学习——第二节:神经网络基础(下)

嵌入式系统:基本定时器

Fiddler tool explanation

php向mysql写入数据失败
随机推荐
基于多块信息提取和马氏距离的k近邻故障监测
Mysql 死锁和死锁的解决方案
moment的使用
唤醒手腕 - 微信小程序、QQ小程序、抖音小程序学习笔记(更新中)
利用Jenkins的持续集成
达梦数据库大表添加字段
pnpm 是凭什么对 npm 和 yarn 降维打击的
Use of thread pool (combined with Future/Callable)
长期招聘嵌入式开发-深圳宝安
DataFrame insert row and column at specified position
吴恩达深度学习deeplearning.ai——第一门课:神经网络与深度学习——第二节:神经网络基础(下)
Qt writes custom controls: one of the text spotlight effects
Basic introduction of stack and queue and C language implementation of functions such as creation, destruction, entry and exit, counting the number of elements, viewing elements, etc., as well as stac
RedisTemplate: 报错template not initialized; call afterPropertiesSet() before using it
MVCC of Google's Fragmented Notes (Draft)
向美国人学习“如何快乐”
Algorithm Supplements Fifteen Complementary Linked List Related Interview Questions
别把你的天使弄丢了
Insights in programming
Data source object management Druid and c3p0