0%

Basic Principle of DNS

DNS, also known as the Domain Names System, is an Internet service used to translate domain names and their corresponding IP addresses into servers.

Domain Names System

Definition

DNS is used to translate domain names into IP addresses. Where.

  1. IP address: a dot-separated set of numbers that uniquely identifies a computer on the Internet
  2. domain name: a dot-separated string of names used to represent the name of a computer

Domain Name Composition

** Domain names are hierarchical, from top to bottom (right to left in writing), divided into root, top level, second level, third level, etc. ** 1.

  1. root domain name: root

  2. Top level domains: net, com, edu, org…

    1. 2nd level domains: ibm, baidu, alibaba, ….

      1. Third level domains: www, mail, …

Note: At each level of the domain name there is a name server, if in the top level domain, there is edu name server, com name server.

Query method

  • Recursive query: A only requests B until B returns the result A wants.
  • Iterative query: A requests B, B returns the result informing A of the other servers it needs to request, then A requests C, D, E etc and gets the return result of the response.

Domain Caching

  • For domain name servers.

    When resolving a domain name for the first time, a cache is used to hold the mapping of the domain name to the corresponding IP address.

  • For local computers.

    • For browsers.

      The browser will use cache to save the actual IP address of the website domain name after it has been obtained to reduce the number of network requests

    • For operating systems.

      The operating system cache is the user’s own configured hosts file

Query process

There are roughly seven steps

  1. first search the browser’s DNS cache, which maintains a table of domain names corresponding to IP addresses, return if available, and end the operation

  2. if not found, continue to search the operating system’s DNS cache, return if available, and end the operation

  3. if not found, the operating system sends the domain name to the local DNS server, which searches its own DNS cache recursively, returns if there is one, and ends the operation

  4. if not found, the local server iterates to the parent DNS server

    1. the local DNS server sends a request to the root DNS server, which returns the top-level DNS address
    2. the local DNS server then sends a request to the top level DNS server, which returns the address of the second level DNS server
    3. the local DNS server then sends a request to the second level DNS server, which eventually returns the IP address corresponding to the domain name

At this point, the request phase is complete and the result is returned to the browser and cached in three steps. 5.

  1. the local DNS server returns the IP address to the operating system and caches the mapping of the domain name to the IP
  2. the operating system returns the IP address to the browser and caches the mapping of the domain name to the IP
  3. The browser gets the IP address of the domain name and caches the mapping of the domain name to the IP