My girlfriend suddenly asked me what DNS is….

This evening I was lying in bed using my cell phone when my girlfriend suddenly said her computer was broken. Said she couldn’t get on the Internet with WIFi. Let me show her. (This is the advantage of having a programmer boyfriend 😂)Then I took a look at the computer and found DNS resolution errors when I visited the web page, so I immediately located the problem. It’s easy to just change the DNS resolution address and enter it in CMDipconfig /flushdnsWe’re done. But suddenly she asked me what DNS was. So I told her……

The body of the

If you want to call your friend, you have to know his cell phone number so that you can establish a communication, and the cell phone number here is the IP address, Because in the computer network is the use of TCP/IP communication and TCP/IP is through THE IP address to determine the communication object, and THE IP address is composed of the dot number 12.11.12.11. If you don’t have an IP address it’s like you don’t know your friend’s phone number but you want to call him. Is that reasonable?

But when you visit a website, you don’t enter an IP address, you enter a name to visit the website. The name is used to convert user-friendly machine names into IP addresses, which is what DNS stands forDomain Name SystemDomain name system. Why use a domain name instead of an IP? In fact, because IP is difficult to remember 😂. Don’t believe me, try to remember ten IPS.

A domain name system is a name system, so why not a name? This is because many domains are used in this Internet naming system, hence the term “domain name.” The domain name system (DNS) clearly indicates that such a system is used on the Internet.

For example, if you want to access the domain name www.baidu.com. Then you need to entrust the operating system to help you query the IP address of the target site, which is not visible to the user. Following the example above, it would be very difficult to remember your friend’s cell phone number. At this point, if you have a phone book, you just need to add a note for each phone number. To contact someone, you just need to look up their phone number in the phone book. DNS, you can think of it as a giant phone book. This DNS works not only for IPV4 but also for IPv6. DNS also belongs to the application layer and provides assistance for application layer software.

Interactive process:

Domain structure

Domain name naming is the use of hierarchical tree structure naming method, that Baidu domain name for example, Baidu’s real domain name should bewww.baidu.com.rootThe general shorthand iswww.baidu.com.And this.It is the root of the domain name. The latter structure is divided into top-level domain name, secondary domain name, tertiary domain name and so on. Domain names after the second level are generally called subdomain names. As shown in figure:As can be seen from the figure above, the domain name is composed of several parts and each part passes through.Split and then joined together on the far right is the root domain, the root domain is not visible to the user. We usually see domain names are like this:Each level of the domain name should not exceed 63 characters (mainly for easy memorization). The other thing is that in a domain name it’s case insensitive but it’s usually lowercase. Moreover, DNS does not specify the meaning of each level of domain name and does not limit the level of domain name. Each level of domain name is managed by the upper level of the domain name authority, and the highest top-level domain name byICANNManage. The advantage of this is that each domain name is unique on the Internet and it is easy to devise a mechanism for querying domain names.

Previously domain names were divided into three categories:

  • Country top-level domain nTLD: for instance,.cnIt stands for China,.usStands for the United States,.ukFor England and so on
  • The generic top-level domain name gTLD: The earliest top-level domains were
    • .com stands for companies and businesses
    • .NET stands for web service organization
    • .org Non-profit organization
    • .edu educational institution
    • .gov government department
    • .int U.S. military organization
  • Infrastructure domain name: There is only one infrastructure domain name, ARPA, which is used for reverse resolution and is commonly referred to as a reverse domain name.

Given that the domain name system is a hierarchical tree structure, the structure of the domain name system on the Internet looks like this:

So now we have another problem. It says there are a lot of domain names so how do you query? If it is the domain name of COM, go to the domain name of COM? If net domain name to net server query?

The DNS server

If you follow the domain name structure above, each domain name requires a server. Now there are a lot of domain names on the Internet and that translates into a lot of DNS. And too many servers will affect the speed of domain name query. It is also impossible to keep all domain names in one server. Therefore, DNS server uses partition method to solve the above problems.

In DNS, the domain managed by a server is called a domain, and each unit divides its domain according to its own situation. Each node is reachable in its own area. Each zone then has its own domain name server, which holds all domain name and IP mapping.

So instead of using domains as units in DNS, you use extents as units. It’s easier to understand the concept of zones.

Actually can take root domain name as a country and top-level domain is a province and so on the secondary domain name is the municipal units, level 3 domain name is the town of county units and units.

So from the figure above we can see that a.com is a city and then the following nodes belong to the jurisdiction of the city of a.com that they only need a domain name server can complete the resolution of all the sub-domain names of a.com. Therefore, the unit of category in DNS server is not domain but area, which is the actual domain of DNS server. In the figure above the relationship between a region and a domain is actually equal to. So let’s look at the picture below.

At this time, C.a.com also divided a region, but it also belongs to the a.com domain. At this time, their relationship is more domain than region. For they all belong to the same domain of a.com, under which there is a division of C.a.com. One region requires one server so now we have two regions that require two domain name servers. So now there’s another question: what is a domain name server?

In fact, in DNS servers are also differentiatedIt is divided into three categories respectivelyRoot DNS server,Top-level domain name server,Permission domain name server.

  • The root DNS server is the highest level DNS server. The root DNS server knows the addresses of all top-level DNS servers. During the resolution process, if the local DNS server cannot resolve the DNS server, the root server is used to query the DNS server. So once the root server goes down all the DNS servers go down. The root server doesn’t do the parsing, it just tells you which top-level server to go to next time.
  • The TOP-LEVEL domain name server manages the secondary domain names registered with the top-level domain name server
  • A domain name server is basically a server that manages a district

How to query DNS

If it does not exist, it checks the operating system cache. If it does not exist, it checks the operating system cache. If the operating system does not cache, it checks the local HOST file. If there’s no record in the HOST file, it’s going to go to the local DNS server. If there’s no record in the local DNS server, it’s going to go to the root server. These DNS servers are usually provided by network operators, or you can set them up manually. There are 13 root servers in the world. Their names are A to M. One primary root server is in the United States and the remaining 12 are secondary root servers, including nine in the United States, two in Europe, the United Kingdom and Sweden, and one in Asia in Japan. All servers are managed by ICANN.

Here are the steps to complete the query:

  • 1. The client browser cache. If there is no cache, query the operating system cache
  • 2. The local DNS server checks whether the local CACHE exists. If no, the local DNS server checks the root server
  • 3. The root server returns to the local DNS server to query the domain, and the local DNS server queries the domain again
  • 4. The local DNS server returns the query result to the client and caches the result.

The following is the flow chart of query a.com:There are two methods for DNS to query the IP address of a domain name: recursive query and iterative query.

Iterative query

An iterative query is a query from the root server to the local server. The feature of iterative query is that when the root DNS server receives a request from the local DNS server, it tells the local DNS server to go to the top-level server, and then the local DNS server goes to the top-level server. If the top-level server tells the local server that it knows the address of the permission server, then the local server queries the permission server. The local DNS server returns the query result to the client.

Recursive query

Recursive query is simple. The local DNS server uses recursive query on the client. If the local DNS server does not know the domain name queried by the client, the DNS server will query the domain name as a DNS client to other DNS servers.

Manual queries

Next, we manually query the DNS of a domain name in the operating system. In Linux, the dig command is used to query host address information from the DNS server.The default output of the DIG command is quite rich and can be divided into about five parts.

  • The first section shows the version of the dig command and the parameters entered.
  • The second part shows some of the technical details returned by the service, most importantly status. If the value of status is NOERROR, the query ends successfully.
  • The “QUESTION SECTION” in Part 3 shows the domain name we want to query.
  • The “ANSWER SECTION” of part 4 is the result of the query.
  • The fifth part is some statistics of this query, such as how long it took, which DNS server was queried, when the query was carried out and so on.

The default dig query is A record. The A in the result returned in the fourth part above means that the query is A record. Dig command explanation There is a lot of information on the web and I won’t go into it here. For more dig command ruan da’s article is recommended here.

www.ruanyifeng.com/blog/2016/0…

DNS record type

type explain
A Address record: Specifies the IPv4 address of A domain name. If you want to point A domain name to an IP address, you need to add A record.
AAAA Specifies the IPv6 address record corresponding to the host name (or domain name).
CNAME If you want to point to another domain name and have another domain provide the IP address, you need to add a CNAME record.
MX If you need to set up a mailbox so that it can receive mail, you need to add MX records.
NS DNS records. If subdomain names need to be resolved by other DNS servers, NS records need to be added.
SOA SOA is a mandatory record in all culture files. It must be the first record in a file.
TXT You can write anything and the length is limited to 255. Most TXT records are used for SPF records (anti-spam).

The last

Note that DNS has a caching mechanism to improve query efficiency. Refresh the DNS cache after modifying the DNS server. The ipconfig /flushdns command at the beginning of this article is designed to flush the local DNS cache.

Shoulders of giants

  • Diagram to TCP/IP
  • www.ruanyifeng.com/blog/2016/0…
  • Tojohnonly. Making. IO / 68-8 E5 DNS % %…
  • How is the network connected
  • zhuanlan.zhihu.com/p/61394192
  • Blog.csdn.net/m0_37263637…
  • Baike.baidu.com/item/%E5%9F…
  • www.cnblogs.com/sparkdev/p/…

Follow me to learn more