DNS: Domain Name System

The common use of DNS is to associate a server name with an IP address, but it can also associate a mail address with a mail server, as well as a name for various messages.

Why do YOU need an IP address

The TCP/IP network determines the communication object by IP address. If the IP address is not known, the message cannot be sent to the peer party. Therefore, you must query the IP address of the peer party before entrusting the operating system to send messages.

TIP: If the Web server uses the virtual hosting function, it may not be accessible by IP address. Because the virtual host is sent on the server of one or more no entity server, access to the domain name of the virtual host, according to the DNS resolution IP access to the entity host, and then the entity host according to the domain name forward to the corresponding virtual host, The IP resolved by DNS is only the IP address of the physical host (not the IP address of the Web application server to be accessed).

Reasons for using domain names and IP addresses

  • Instead of using an IP address, use a name to identify the communication object. Okay? The length of an IP address is 32 bits (4 bytes), and the domain name can be up to 255 bytes, which increases the burden of the router and takes longer time to transmit data, resulting in low operation efficiency. (Routing and forwarding packets to transmit data)
  • Do not write the name of the server in the browser address, directly write the IP address? Substituting IP addresses for server names also works. However, it is also very difficult to remember a string of IP addresses made up of numbers
  • Let people use names, let routers use IP addresses. To bridge the gap between the two, there needs to be a mechanism to look up IP addresses by name, or names by IP address, and that mechanism is DNS

The structure of the TCP/IP

TCP/IP is the subnet is composed of a small, through a router connected to form a larger network (subnet: use a hub connecting several computer), all of the devices in the network will be assigned an address, this address is in reality a road of “* *, * * room”, (no. : assigned to the whole subnet, room: The number assigned to the computer in the subnet is called the network number, and the number assigned to the room is called the host number.) The whole address is called the IP address. From the IP address, we can determine where to access the object server and send messages to the server

The sender sends the message hub in a subnet, forwarded to the nearest router, the router will be based on message destination to judge the location of the next router, and then send the message to the next router (that is, the news again after a subnet hub is forwarded to the next router), the process repeats itself, the final message is transmitted to the destination.

Actual IP address

The actual IP address is a string of 32 bits of numbers divided into four groups of 8 bits (1 byte), which are expressed in decimal notation and separated by dots.

In IP address rules, the network number and host number are connected in 32 bits. However, the structure of the two parts is not fixed (users can determine the allocation relationship between them when forming a network). It is impossible to distinguish which part is the network number and which part is the host number. Therefore: Additional information is required to represent the internal structure of the IP address. This requires a subnet mask. The subnet mask is a string of 32 bits with the same length as the IP address. The left half is 1 and the right half is 0. The part whose subnet mask is 1 indicates the network ID, and the part whose subnet mask is 0 indicates the host ID.

Host number of the IP address:

  • All 0: indicates the entire subnet
  • All 1: sends packets to all devices on the subnet.

How does the browser issue a query to the DNS server

  • The browser searches its OWN DNS cache: first, the browser searches its OWN DNS cache to see if it has expired. If it has expired, the resolution of the cache is finished. (The chrome cache only lasts one minute.
  • Search for the DNS cache of the operating system: If the browser does not find the CACHE or the cache expires, the browser searches for the CACHE of the operating system. If the cache does not find the cache or the cache expires, the parsing ends.
  • Read the local hosts file: If the cache of the operating system is not found or invalid, the browser reads the local hosts file. (The hosts file can also set up binding relationships between domain names and IP addresses. You can edit the hosts file to resolve the names. For example, if we want to block a domain name, we can point the address to a non-existent IP address.
  • The browser makes a DNS system call: if no configuration item is found in hosts, the browser makes a DNS call (to the local master DNS service, usually provided by your carrier).

The interaction between the parser and the DNS server

The search for an IP address through the DNS is called domain name resolution, and the person who performs the resolution is called a parser. A parser is actually a program that is contained in the operating system’s Socket library (which allows other applications to call the operating system’s network functions).

The parser’s usage is very simple, writing applications (here is the point at which the browser), write the parser program name below (gethostbyname) and web service domain name (http://www.lab.glasscom.com/) it is ok to make calls, This completes the call to the parser.

Application invocation parser diagram:

The workflow flow of the entire parser:

  • After invoking the parser, it sends a query message to the DNS server (provided by the carrier).
  • Find corresponding operator service will find its own cache entry, has not expired, parsing is successful, if not find corresponding entries, master server will replace the browser has launched an iterative DNS request, first find the root of the domain), the operator to get the domain name server IP, returned to the operating system kernel, cached in its own cache area at the same time, The OPERATING system kernel returns the IP address from the DNS service provider to the browser.
  • When the browser sends a message to the Web server, it simply fetchs the IP address from the memory address and gives it to the operating system along with the HTTP request message.

When sending a message to the DNS server, we also need to know the IP address of the DNS server. However, the IP address is set up as a TCP/IP setup item, so there is no need to query it.

Basic work of the DNS server

The basic job of a DNS server is to receive a query message from a client and return a response based on the message content

The query message from the client contains three types of information

  • Domain name: the name of the server or mail server (the part after @ in the mail address).
  • Class: information used to identify networks (DNS applications on networks other than the Internet were also considered when the original DNS scheme was designed. However, there are no other networks nowadays, so the value of Class will always be IN for the Internet.
  • Record type: indicates the record type of the domain name (for example, A: indicates that the domain name corresponds to an IP address,MX: indicates that the domain name corresponds to A mail server. The server returns different information to the client for different record types.

The DNS server stores records corresponding to the preceding three types of information. The DNS server searches for records based on their domain names and record types and returns response messages to clients.

How is information on a DNS service registered and saved on a DNS server

All information in the DNS server is stored in a hierarchical structure of domain names, divided by dots: host names. Secondary domain. Top-level domain. Root (host. SLD. Tld.root), the higher the level as you get closer to the right. All domain names are followed by the root domain, but they are generally omitted.

Secondary domain name is a domain name that users can register, and the next level is the host name, also known as the “tertiary domain name”, which is the name that users assign to the server in their own domain, and the user can assign any name.

As mentioned above, if the carrier service does not find the corresponding entry, it will initiate a DNS iteration request. The first is to find the root domain server, so the carrier service must keep the IP address of the root domain service. There are 13 root logical DNS servers in the world: A-M, and there are 386 real root servers according to statistics in 2014. It is not difficult to save the DNS server information of the root domain in all DNS servers on the Internet. How to do this: Information about the root DNS server is already included in the configuration file of the DNS server program, so this information is automatically configured once the DNS server program is installed.

An iterative request initiated by the carrier DSN server

First, from the configured information services operators get the IP address of the root domain name (only one, it is assumed that the root domain is actually want to 13 root domain initiate requests), and like a root domain the initiating group asked: “what is the IP address of the http://www.lab.glasscom.com, please?” “, the root domain name query records data did not find, answer: “I do not know its IP address, but I know.com authoritative server (NS) address, it is XXX.xxx.xxx.xxx, you go to ask it. The IP address of the operator service operators get. Com, according to the IP address by another request to ask. Com server ask: “is the IP address of the ns of http://www.lab.glasscom.com, please?” The.com domain server searches for its own records and replies, “I don’t know. I only know the IP address of http://glasscom.com.” And so on, as long as the repeat the previous steps, you can ultimately find the target DNS server, as long as the target the DNS server to send a query message, can get the answer we need, also is the IP address of http://www.lab.glasscom.com.

Caching speeds up DNS server responses

  • On the Real Internet: One DNS server can manage information about multiple domains, and the upper-layer AND lower-layer domains share the same DNS server. When accessing the upper-layer DNS server, you can skip the upper-layer DNS server and directly return information about the upper-layer DNS server.
  • The DNS server has caching capabilities: instead of starting a search from the root domain, the response can be returned directly through the cache, and subsequent queries can proceed down from the cache location. Caching can reduce the time it takes to query rather than looking up from the root domain every time.
  • After the information is cached, the original registration information may be changed. In this case, the information in the cache may be incorrect. Therefore, the validity period of the information in the cache is set.

Command to view the entire DNS request process:

Display the entire query process: dig http://www.baidu.com dig +short http://www.baidu.com

For more query commands, please refer to Mr. Ruan Yifeng’s article: INTRODUCTION to DNS Principles – Ruan Yifeng’s Weblog