preface

DNS & CDN

What I don’t know what to learn about the cache, we often mentioned is the browser cache and HTTP cache, the most talked about is strong cache and cache such negotiations, but the corresponding DNS cache (and related knowledge), or a CDN cache (and related knowledge) is not particularly clear, may involve not only of the cache, while others, such as DNS lookups, CDN principle, Process and so on, today by recording this article, to understand some more knowledge about them.

I hope that after finishing the article, I can clear up the following questions:

  1. What is DNS? Why do you need DNS?
  2. How does DNS look up? Recursive, iterative query?
  3. What is DNS cache? What is involved in DNS queries?
  4. What is CDN? Why?
  5. What is the relationship between CDN and DNS?
  6. What is the specific CDN process?

.

There must be something wrong with this article. Please leave your valuable suggestions in the comments section. Well, let’s get started.

1. What is DNS?

In terms of DNS, what I’m thinking is that the interview question is “enter the URL to the page to show what’s going on”. In this process, we first determine that if the URL is a domain name, then domain name resolution is required.

So why do domain name resolution?

On the Internet, communication is based on TCP/IP protocol

The IP protocol is referred to as the agreement, if the TCP | UDP defines the data transmission way, then through the IP protocol, we can know the location of the data transmission. However, we can also access the corresponding address through the domain name, and in fact only the IP address can find the corresponding server, so when you use the domain name to access, the first experience is a domain name resolution process, the domain name into the corresponding IP address, and then to address.

DNS is a domain name system that translates domain names into IP addresses. You can use it as a translator.

DNS belongs to application layer protocols (including HTTP SMTP FTP)

2. DNS domain name resolution process

  1. The client running this DNS on the user’s host (i.e. our PC or mobile client)
  2. The browser extracts the domain name field, the host name of the visit, from the received URL and passes this host name to the DNS application client

http://www.baidu.com/ like an address like this

  1. The DNS client sends a query packet (containing the host name field to be accessed) to the DNS server.
  2. The DNS client finally gets a reply message containing the IP address corresponding to the host name
  3. The browser receives the IP address from the DNS server and initiates a TCP connection to the HTTP server located at the IP address

3. DNS service system

[I will combine my own understanding to draw some pictures, maybe not clear, you can combine your own understanding to clarify]

In the DNS server, you can find the corresponding IP address to return the domain name. In the DNS server, you can find the corresponding IP address.

Note the following: The DNS client of the user host sends a DNS query packet to the network. The UDP datagrams used by all DNS request and reply packets are sent through port 53.

  • A UDP name server exchange can be as short as two packets: a query packet and a response packet.

  • A TCP exchange contains at least nine packets: a three-way handshake to initiate a TCP session, a query packet, a response packet, and a packet exchange for four breakups.

For efficiency reasons, TCP connections are expensive. Therefore, UDP is used as the transport layer protocol of DNS, which results in only 13 root DNS servers.

  1. When we type in the browserhttp://www.baidu.com/Is displayed, the operating system checks whether the local hosts file has the corresponding IP address mapping. If yes, directly invoke the command
  2. If not, look for the local DNS resolution cache, if there is a direct call
  3. If not, (there is a preferred DNS server set in TCP/IP, that is, a local DNS server), if there is a mapping on the server, return the IP
  4. If both zone files and cache resolution fail on the local DNS server, query the DNS file based on the local DNS server Settings (whether forwarding is enabled)

The whole process above is recursive query

  1. No forwarding:
  • The local DNS sends the request to the 13 root DNS servers. Upon receiving the request, the root DNS server determines who is authorized to manage the domain name (.com) and returns an IP address that is responsible for the top-level domain name server

  • After receiving the IP information, the local DNS server will contact the server responsible for the.com domain. The server in charge of the.com domain receives a request and if it cannot resolve the request itself, it will find a DNS server address of the next level that manages the.com domain and give it to the local DNS server.

  • After receiving the address, the local DNS server searches for the domain server and performs the preceding operations until it finds the WWW. Baidu.com host.

  1. There are forward:
  • This DNS server will forward the request to the upper-level DNS server, which will parse it.

  • If the upper-level server fails to resolve the problem, the upper-level server searches for the root DNS server or forwards the request to the upper-level server.

  • Whether the local DNS server uses a forward or root prompt, the result is eventually returned to the local DNS server, which in turn returns the result to the client.

The whole process is iterative query

The client to the local DNS server is the ground cabinet query, and the interactive query between DNS servers is the iterative query

3. Summary of DNS search

  1. DNS cache on the client
  • Browser cache
  • System cache hosts
  • The routing cache
  • ISP DNS cache
  • There are 13 root DNS servers
  • Top-level domain name server
  • Master domain name server
  • Save the result to the cache

4. What is CDN?

Content delivery network

It can be simply understood as a server that is very close to users and can obtain complete original data from the server. It will synchronize with the server with original content periodically to ensure that users can obtain the latest content from the server.

CDN can greatly change the download speed, improve bandwidth, accelerate the website access — the physical distance between the user and the content is shortened, the user waiting time is also shortened.

The CDN server is closer to the client than the original content server

Traditional:

Use the CDN:

  1. So you can set up a cache server close to the user, make a copy of the remote content,
  2. CDN is to adopt more cache servers (CDN edge nodes), which are placed in relatively concentrated areas or networks where users access.
  3. When the user visits the website, the global load technology is used to direct the user’s access to the nearest cache server, and the cache server responds to the user request.

5. Specific process of CDN?

When deploying the CDN network, we use the URL to access, and the DNS domain name resolution process is a little different, specifically look at 🌰 :

For example, we are now going to Tencent video on demand a TV series 📺 :

  1. When we click the content on the app, the app will also go to the local DNS domain name resolution system to seek IP address resolution according to the URL
  2. The local DNS system will give the domain name resolution rights to our DNS server dedicated to the CDN
  3. CDN dedicated DNS server,Add the global load balancing device IP address of the CDNBack to the user

  1. A user sends URL access requests to the load balancing device of the CDN based on the IP address
  2. The CDN load balancing device selects a cache server in the region to which the user belongs based on the USER IP address and URL requested by the user.
  3. The load balancer tells the user the IP address of the cache server and sends a request to the selected cache server
  4. The user sends a request to the cache server. The cache server responds to the request and sends the content required by the user to the user terminal
  5. If the desired content is not on the cache server, the cache server requests the content from the site’s source server.
  6. The source server returns the content to the cache server, and the cache server sends the content to the user. The cache server determines whether to cache the content to the cache server based on the user-defined cache policy.

6. The CDN

I believe that you must have a general understanding of the whole process of CDN.

(1) The accelerated resources of CDN are bound to the domain name. The local DNS server assigns domain name resolution rights to the CDN dedicated server

(2) To access resources by domain name, first of all, DNS searches for the IP address of the nearest CDN node (edge server) (which uses CDN load balancing device), and users can find this device, which is the IP address provided by the previous CDN dedicated server

(3) When accessing the actual resources through IP, if there are no cached resources on the CDN, it will request resources from the source site and cache them on the CDN node. In this way, the CDN node will have the cache of corresponding resources when the user accesses the CDN node next time.

Write it on the back ❤

This article is here for the time being, some superficial understanding of DNS and CDN, but there is no real practice, but some theoretical knowledge should be mastered first.

I am Jing big

A senior student silently preparing for the autumn enrollment.

I hope I can learn and progress with you

wx: lj18379991972

Welcome 👏🏻 to add friends, learn front-end together. ❤

Referenced many excellent articles ❤ :

Alibaba tao department technology zhihu answer

What exactly is a CDN

DNS Domain name Resolution

DNS principles and resolution process

DNS Query Process