Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

preface

Recently opened the daily learning series, every day to the excellent front step closer! Knowledge points will try to use their own words for a summary!

The IP address

An IP address is a unified address format provided by the IP protocol. It assigns a logical address to each network and each host on the Internet to mask physical address differences.

Some of the Internet uses IPV4 IP addresses. There are four digits, each of which can be up to 255 (8 binary digits, up to 2 ^ 8). For example, the local address 127.0.0.1 is commonly used.

The domain name

Domain names are organized in hierarchies. The part to the right of the last “.” of a complete domain name is called a top-level domain, such as.com

Top-level domain names

There are two types of top-level domains

  1. Country top-level domains, such as.cn for China and.us for the United States.
  2. International top-level domains, such as com for businesses,.org for non-profit organizations

The DNS

DNS resolution is to resolve a Domain Name into an IP address. DNS(Domain Name System) is the Abbreviation of “Domain Name System”. Usually, we use the Domain Name to access the website, for example

www.baidu.com, but computers don’t recognize domain names when communicating, they only recognize IP addresses. Addresses on the Internet are numeric IP addresses, and domain name resolution is mainly used for easy memorization.

The following I with our front-end thinking, the DNS resolution analogy for the front-end to send requests to the back-end to obtain the data you want to analyze the DNS resolution process. First question, how does the browser know which address to send a request to resolve the DNS address, this is not a doll! In fact, we can look up our IP address in the network Settings of the computer.

This machine is the cache

After entering the domain name, the computer first checks whether it has the corresponding domain name cache. If it does, the cache can be directly accessed by the IP in the cache. You can enter this command to check ipconfig /displaydns

Hosts file

The hosts file is located in the path C:\Windows\System32\drivers\etc. You can open it on your computer to speed up domain name resolution. For frequently visited websites, you can configure the mapping between domain names and IP addresses in the hosts file. So when we type in the domain name, the computer can quickly resolve the IP instead of asking the DNS server on the network.

Local domain name resolver

If it is not in the hosts file, we need to access the local DNS server. In windows10, you can view the DNS server of your computer in view network properties, as shown in the following figure

Root DNS server

The local DNS server accesses the root DNS server, and the root DNS server returns the corresponding top-level DNS server address of.com or.cn, depending on whether your domain name is.com or.cn. The root server is mainly used to manage the home directory of the Internet. It was originally IPV4, and there are only 13 in the world

One primary root server is in the United States, operated by Network Solutions, an American Internet agency. The remaining 12 are secondary root servers, including nine in the US, two in Europe (UK and Sweden), and one in Asia (Japan).

Top-level domain name server

Then send a request to the top-level domain name server (TLDNS) for our domain name, such as oil.com, and the TLDNS will resolve the corresponding DNS server for our domain name.

Domain name server

Then we send a request to our DNS server with the full domain name as a parameter, and finally we get our IP address, and our local DNS server returns the IP address to the browser, and the browser can send a request to our own server. In the process of querying IP address will also give our local DNS server and browser to add cache, the next visit will not have to query!

Recursive + iterative query

In the process of DNS query, we use recursive + iterative query.

For example, I believe that we have experienced the exam, if the invigilator of the exam paper is personally from the first student to send back, until they go to the last student there to send the last sheet, that is iteration.

And recursion is the teacher will give a few papers to the first student, the first student took a paper passed to the next student, the next student took another one, until the last student there, so it is recursion.

The DNS uses recursion before the local DNS server queries, while the local DNS server iterates to the top-level DNS server and root DNS server.

DNS uses UDP for transmission

DNS using udp transmission because when they visit some less popular sites, we may have to go through all of the above request process, if use the TCP transport we need constantly to initiate a TCP connection, while udp does not need to, and let’s DNS resolution request is very simple, is I give you a domain name, you against me an IP address.

For example, let’s send a request to the back end, send a request to the back end to take ten data and send ten requests to take a data time comparison, it must be shorter to send a request.

DNS resolution record type

When we buy a domain name in some cloud service platforms, we need to resolve to our server IP. When we add the resolution type, we can see that there are many types. Their specific differences I use Tencent cloud DNspod to explain the picture to show

conclusion

DNS resolution actually like our request to pass through one by one server, and finally with the help of the server we got what we want from the database data, during want to speed up the request, of course, is the use of lightweight packets and some caching mechanism to speed up the request, after all, this is just our real request is the first step!

I am new oil, welcome to pay attention to grow together