Most of you are familiar with CDN. Its full name is Content Delivery Network, which translates to Content Delivery Network. It provides a large number of cache servers on the edge nodes of the network, enabling users to obtain the requested content from the nearest edge node rather than the further (meaning longer) business server, thus improving the speed of obtaining content and improving user experience.

At present, cloud server vendors all provide CDN acceleration services, such as:

  • Tencent Cloud-CDN
  • Aliyun-CDN

For example, if a user requests the resource www.test.com/index.html, the CDN will first resolve the domain name www.test.com to the IP address of the nearest server and then make a request to that IP address. Get the /index.html resource.

So, how does CDN resolve the requested server domain name into the nearest IP address?

There are three key points:

  • usingCNAMEAbility to get it rightwww.test.comDomain name resolution becomes resolution of a specific CDN domain name, as shown in the figure belowwww.test.com.cdn.dnsv1.com
  • CDN service providers maintain a huge and accurate IP address database, which can judge the client’s location, network operator and other information according to the IP address of the client.
  • When parsingwww.test.com.cdn.dnsv1.comWhen the domain name IS IP, a request is made to the DNS domain name of the CDN service (step 2 in the following figure). At this time, the DNS domain name of the CDN service can return a cache server IP address nearest to it according to the IP address of the user client

Tencent cloud document has a very clear picture:

I can take my own domain name as an experiment. Elvinn. cn has enabled the acceleration function of Cloud CDN. When executing dig elvinn.cn command for DNS resolution, the following results can be obtained:

; <<>> DiG 9.10.6 <<>> elvinn.cn; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3183 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 3, ADDITIONAL: 15 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ;; QUESTION SECTION: ; elvinn.cn. IN A ;; ANSWER SECTION: elvinn.cn. 600 IN CNAME elvinn.cn.cdn.dnsv1.com. elvinn.cn.cdn.dnsv1.com. 600 IN CNAME tcb-0006158d.tcb.cdntip.com. Tcb-0006158d.tcb.cdntip.com. 600 IN A 14.215.166.141Copy the code

From lines 13-15, it is clear that domain name resolution goes through the following process: Elvinn.cn -> elvinn.cn.cdn.dnsv1.com -> TCb-0006158d.tcb.cdntip.com -> 14.215.166.141, The resulting 14.215.166.141 is the nearest cache server IP address.

Using tools (such as IP.cn), you can find 14.215.166.141 in the telecom machine room in Guangzhou, Guangdong Province, which is really close to me.

Welcome to visit my blog – Rotten pen