This article refers to [Graphic TCP/IP]
In the previous article, I learned that IP is used to identify the host in a certain network area, so we usually do not enter the IP to visit when we visit the website. For example, you visit Baidu, generally enter: www.baidu.com
then you will not always similar input 124.23.1.12
this IP to access it
Put yourself in it and think about it. If you want users to remember your website, you can't let them remember a large number of numbers. What's more, when IPv6 is used in the future, there are more numbers to remember, so the best way is to give these IPs A name, we call it a domain name , and when we visit these domain names, the specific IP to access must be left to DNS . This article will also introduce the specific function of DNS in detail.
- Official account: front-end impression
- There are book delivery activities from time to time, remember to pay attention~
- After paying attention, reply to the corresponding text to receive: [Interview Question], [Front-end must-read e-book], [Complete code of data structure and algorithm], [Front-end technology exchange group]
Explain the specific role of DNS in detail
1. Domain name
At the beginning of the article, I briefly introduced what a domain name is, so let’s take a look at what a domain name looks like
For example, our common www.baidu.com
, baidu.com
that is, Baidu official website domain name, which baidu
is a name for themselves, when Baidu application for the domain name, .com
is indicated by the domain name server belongs to, where we will this domain name is called top-level domain , you can also call it a domain name
Some domain names, for example, example.cn.com
called secondary domain , example.mail.cn.com
called three domain ......
Generally speaking, it can be understood that there are several domain names, which are .
called several-level domain names.
Now available in all domain names are managed by a server, for example .com
by the com服务器
administration, .cn
the cn服务器
management
Then these domain name servers are managed by a root server, so their hierarchical relationship is like a tree structure, as shown in the following figure:
Figure, com服务器
within a cn
server, and cn服务器
within and manages a mail服务器
such a hierarchy can be used to get three domain names example.mail.cn.com
corresponding IP address of the
Therefore, we can call the domain names of all nodes at level 2 of the tree structure as the first-level domain names ; call the domain names of all nodes at level 3 as the second-level domain names ; and the domain names of all nodes at level 4 Is the third-level domain name , and so on
2. DNS
DNS (Domain Name System) is actually a system that manages the effective relationship between domain names and IP addresses, which is equivalent to a large database
When our host requests a webpage through a domain name, it will first send a request to the DNS server we set, and then the DNS server will send a request to the nearest root server, and the root server will return the IP access address of the first-level domain name server to DNS Server, then the DNS server will access the corresponding domain name server according to this IP address. If the domain name has multiple levels, the domain name server will then return the IP address of the next level domain name server to the DNS for its in-depth access
We look at access to example.mail.cn.com
a simplified process diagram
In order to improve efficiency, the DNS server also provides a technology called cache , which is used to store the IP of the domain name server that has been accessed for a short time. Therefore, the real order of the DNS server is not to send a request to the root server first, but to query first. Whether there is the IP address you want to obtain in the cache, if there is, return it directly to our host; if not, follow the above process to request
Suppose we have just visited the request example.mail.cn.com
when, then again, this time requesting the domain name corresponding URL can be read directly from the cache real IP address, the process as shown:
In fact, the cache time of the DNS server will not be particularly long, because if you cache the IP after the first visit, and then the original IP address is changed at this time, then every time we visit the old IP address, it will continue Error, so the cache time is shorter to avoid such problems
Three, conclusion
Welcome to pay attention to the public account: front-end impressions , update the front-end interview questions from time to time, learn the front-end with me, and get an early offer from major manufacturers