DNS Resolution Process

DNS is the process of resolving a domain name into an IP address, which is a very important knowledge point. When entering a URL, the first step is to convert the URL into an IP address through DNS. The browser process is as follows:

(chrome://net-internals/# DNS) (Chrome ://net-internals/# DNS

2, then, the browser will first look for the DNS cache in the operating system, on Windows, the ipconfig/ displayDNS command line to view, on Linux, the NSCD cache service; If not, proceed to the next step

3, from the computer host file, this we often configure; If not, proceed to the next step

4, request the local DNS server (can be considered to be provided by your network access server provider, such as China Telecom, China Mobile, Ali Cloud and other domain name providers), if the server has cache, then directly return, if not, then the next step… Commonly 80% is ok here (for instance you apply for a domain name, go Ali cloud, so you can write the IP that domain name place points to for sure).

5, if the previous step is not successful, then you need to iterate to the root DNS server, see below:

Preparation:

  • The first thing to know is that there are about a dozen root DNS servers and top-level DNS servers around the world. They are the top of the line.

  • Secondly, actually our website should be test.baidu.com. Pay attention to the following points, but the browser has omitted them for the convenience of users.

For example, how to parse test.baidu.com into IP address? It can be described as right to left

. -> .com -> baidu.com. -> test.baidu.com

(1) Request the root DOMAIN name server, with test.baidu.com., the root domain name server found that the end is.com, and then tell you, I only know the IP address of the com top-level domain server, you go to ask it to try

(2) Then the browser requests to the com top-level domain server, with test.baidu.com, com top-level domain server only knows baidu.com. The address of the server where the test is located, does not know what test. This secondary domain name is only known by Baidu itself, because it is set by Baidu itself, just like CRm.credit.cn, is it only the company that knows what CRM is? . So the com TOP-LEVEL DOMAIN server will tell you that I only know Baidu.com. IP address, you ask it to put (Baidu web server)

(3) Then to the “Baidu company domain name server” request, with test.baidu.com. Baidu company itself must know what test is, so Baidu company, the last real IP address, returned to the browser, here, the iterative query completed

Think: Why do we need iterative queries?

If there is no layering, then all the domain names in the world are managed by the root server? Isn’t that a mess?

Therefore, the domain name is layered to facilitate management

As you can imagine, crM.Credit.com is where the company’s operations are headed

Then credit.com, which is www.credit.com by default, is the domain name the company applied for on the com domain name server

The com DNS server must be registered with the root DNS server

Front-end DNS optimization

1. Reduce DNS query times

DNS queries take time, but because DNS can be cached in browsers and computers for a period of time, the domain name is usually resolved only the first time a web page is loaded.

Therefore, minimize the number of requests for different domains, such as downloading external resources to servers with the same domain name in advance.

2. DNS pre-resolution

The principle of preparsing is that when an HTML is loaded, the href links contained in the A tag are automatically parsed as IP addresses and cached, such as

// index.html
<html>
    <a href="test.baidu.com"></a>
</html>
Copy the code

When index. HTML is loaded, test.baidu.com is parsed. if you click to visit test.baidu.com, DNS parsing is not required.

Note that in HTTPS pages, it is not automatically pre-parsed, so you need to add it manually

<link rel="dns-prefetch" href="//img.alicdn.com">
Copy the code

You can also enable automatic parsing of all links

<meta http-equiv="x-dns-prefetch-control" content="on">
Copy the code

Note: Not all pages need to be parsed manually, this is usually done on the entry page of the entire site, after all, most of the domain names used under a site will be displayed on the home page

DNS Prefetch is a generic solution for optimizing web page performance, perhaps even more so for internationalized sites. The cost of learning and understanding is low, so you can use your own web pages with confidence

Principle of CDN

The DNS described above is a process without introducing a CDN. If a CDN is used, the process will change.

CNAME

The first thing you need to know is what a CNAME is.

1, A record

The Address record is not an IP Address or a domain name. It can be understood as a pointing relationship:

  • Domain name www.xx.com → 111.111.111.111

  • Host name DD → 222.222.222.222

It can be understood as the record of the final mapping between the domain name and IP, which is A record

2, CNAME

Why distinguish between A record and CNAME? We can call a CNAME record an alias record, which is a nickname.

For example, A is recorded as:

www.credit.com – > 111.111.111.111

There may be multiple CNAME records

www.100fen.com → www.credit.com

www.baifen.com → www.credit.com


So you get the idea, CNAME is the nickname of your primary domain A record

CNAME refers to record A, and record A refers to A specific IP address.

A url can have multiple Cnames, can be understood as domain name forwarding

CDN process

The full name of the CDN is Content Delivery Network. Its purpose is to add a layer of new network architecture in the existing Internet process, the content of the website is published to the closest to the user’s network “edge”, so that users can get the required content nearby, solve the Congestion of the Internet network, and improve the response speed of users to visit the website. From the technical comprehensive solution due to the network bandwidth is small, user access to large, unequal distribution of outlets, to solve the user access to the site response speed slow root cause.

Benefits of using CDN?

  • Speed up page loading

  • Handle high traffic loads

  • Don’t need? This complete localization overlay

  • Reduce bandwidth consumption

  • Load balancing across multiple servers

  • Protect your site from DDoS (denial of service) attacks

How does a CDN work in general?

In the previous DNS resolution step 4, the request was made to the local DNS server (think of it as your network access server, such as China Telecom or China Mobile)

After the introduction of CDN, this step changes.

We treat the local DOMAIN name server as the domain name product in Aliyun, and we treat www.credit.com as the domain name we applied for from Aliyun.

If there is no CDN, we can directly configure www.credit.com → 111.111.111.111, so in general, DNS step resolution 5 iteration query, in fact, is not needed.

If we want to introduce a CDN,

In ali Cloud console, we can set several CNAME configuration for www.credit.com domain name, for example, we configure:

  • CNMAE records: www.credit.com → cdn.credit.com

  • A Record: cdn.credit.com → 222.222.222.222

How is the CDN optimized

Load balancing

The CDN load balancing device selects an appropriate cache server to provide services for users.

The basis for selection includes:

Determine which server is closest to the user based on the user IP address.

According to the content name carried in the URL requested by the user, judge which server has the content required by the user;

Query the load of each server to determine which server has the lowest load.

Based on these factors, the load balancing Settings return the IP address of the cache server to the user.

The cache

The cache server responds to the user’s request and delivers what the user wants to the user.

If the cache server does not have the content the user wants and the load balancer still distributes it to the user, the server requests the content from its upper-level cache server until the source server that traces back to the site pulls the content locally.

Caching also involves a lot of algorithms, such as efficient data structures and algorithms that trade space for time, multilevel caches that are differentiated by heat, SSDS at the front and mechanical disks at the back…

CDN summary

After introducing CDN between the site and the user, the user will not feel any different from the original.

Websites that use THE CDN service only need to give the resolution of their domain names to the load balancer of the CDN. The LOAD balancer of the CDN will select an appropriate cache server for users. Users can access the cache server to obtain the data they need.

The cache server is deployed in the equipment room of the network carrier, which is the network service provider of users. Therefore, users can access the website with the shortest path and the fastest speed. Therefore, CDN can accelerate the user access speed and reduce the load pressure of the source center.

Summary of DNS and CDN overall process

For example, we request the www.credit.com domain name

(chrome://net-internals/# DNS) (Chrome ://net-internals/# DNS

2, then, the browser will first look for the DNS cache in the operating system, on Windows, the ipconfig/ displayDNS command line to view, on Linux, the NSCD cache service; If not, proceed to the next step

3, from the computer host file, this we often configure; If not, proceed to the next step

4. Request the local DOMAIN name server (which can be considered as domain name provider such as Aliyun),

It is found that ali Cloud has been configured, CNMAE records: www.credit.com → cdn.credit.com, so at this time, tell the browser to request cdn.credit.com

At this point, the browser requests cdn.credit.com, and steps 1-3 above must be repeated…

Repeat steps 1-3

4. Request the local DOMAIN name server (which can be considered as domain name provider such as Aliyun),

Ali Cloud has been configured, A record: cdn.credit.com → 222.222.222.222, and then the IP 222.222.222.222 returned to the browser.

5. The browser gets the IP address. Note that this IP address is actually the ADDRESS of the CDN load balancing server… Continue requesting this address

6. After the request enters the CDN load balancing server, the server will return the most appropriate file cache server IP address according to the algorithm strategy, etc. As for how to choose the appropriate, see the following optimization

7. The browser accesses the IP address of the file cache server and finally obtains the file resources