What is DNS?
The Domain Name System (DNS) is a hierarchical and distributed Domain Name System. It is mainly used to convert domain names into corresponding IP addresses.
The Domain Name System (DNS) is The phonebook of The Internet
Whenever a user visits a web site, www.baidu.com, type the URL, and DNS begins to resolve the current domain name to find the corresponding IP address.
It’s as if I wanted to call my friend today but didn’t remember his phone number. I finally found a number in the phone book. DNS domain name resolution does something similar.
DNS is like a huge object that stores a lot of key-value pairs. Key is the domain name and value is the IP address.
How does DNS resolve domain names?
When there is no cache for DNS resolution, hierarchical query is required. Let’s start by reviewing the structure of DNS domain names.
DNS Domain name Structure
- The root of the domain name
root domain
For example, the domain name www.baidu.com appears as www.baidu.com.(short), but is actually www.baidu.com.root. This is not an oversight, but at the end of all domain names, there is actually a root domain name. And the root domain is the same.
- Top-level domain names
top-level domain
(TLD)
The next level of the root domain is called a top-level domain, such as.com or.net.
- Secondary domain name
second-level domain
(SLD)
The next level is called “secondary domain”, for example, at www.baidu.com. Baidu, which is the domain you can register.
- The host name
host
(Level 3 Domain name)
The next level is the host name, such as WWW in www.example.com, which is the name assigned to the server by the user in his domain and can be assigned by the user at will.
To sum up, the structure of a domain name is as follows
Host name. secondary domain name. Top-level domain name Root domain name host. ssl.tlD. rootCopy the code
DNS Query Process
In the absence of caching, a DNS parser performs an iterative query in eight steps.
- Suppose the user is typing in a browser
example.com
After the DNS query request is sent over the network by the DNS resolver (DNS resolver
Received). DNS resolver
The root server is queried first.- The root server then returns a top-level domain based on the domain name at the far right of the URL
TLD
Server address (.com or .net
) to the parser. - After receiving the TLD server address from the root server,
DNS resolver
A domain name resolution request is sent to the address. - When the TLD server receives the request, it parses it and converts it
example.com
DNS server IP address sent toDNS resolver
DNS resolver
Send the query request toexample.com
Domain name serverexample.com
The domain name server willexample.com
The IP of the website is sent toDNS resolver
- In the end,
DNS resolver
Send the IP address to the browser - After receiving the IP address, the browser sends the
example.com
The server sends a request example.com
The server receives the request and responds, returning the resource
With caching, DNS resolution is performed locally on the client:
- Browser DNS Cache
- System DNS Cache
- Router cache
- ISP caching
DNS cache
Sometimes in order to shorten the overall DNS query time, DNS cache
- Browser DNS Cache
By default, modern browsers cache DNS records for some time. When DNS parsing starts, the browser cache is the first place to visit.
In Chrome, you can check DNS cache by visiting Chrome ://net-internals/# DNS
- System DNS Cache
The system DNS cache is the last stop of the local DNS cache. If no IP is found here, leave the local search.
The OS cache will refer to the TTL value of the DNS server response, but not exactly the TTL value.
- ISP Carrier Cache
The broadband operator’s own cache
DNS resolution query mode
Each terminal is a client of the DNS server, also called a DNS resolver. It sends a domain name resolution request to the DNS server and then finds the corresponding IP address. There are three types of DNS resolver query modes:
- Iterative queries, starting with the root DNS server, run downwards until a resolution succeeds or fails.
- Recursive – A DNS parser queries a DNS server that implements the parser function and asks the server to return results, whether successful or unsuccessful.
- Non-recursive – similar to the iterative, but queries are run using the CACHE of the DNS parser.
Domain name types
There are several types of domain names, which we also call the “record” type. It corresponds to the correspondence between domain names and IP addresses:
(1) A: Address, which returns the direct mapping between domain name and IP Address.
(2) NS: Name Server, which returns the address of the Server that stores the next-level domain Name information. The record can only be set to a domain name, not an IP address.
(3) MX: Mail eXchange, which returns the address of the server that receives emails.
(4) CNAME: Canonical Name, which returns another domain Name, i.e. the current query is a jump to another domain Name, see below.
PTR: Pointer Record, which is only used to query a domain name from an IP address.
Generally speaking, for the security and reliability of the service, there should be at least two NS records, and there can be multiple A records and MX records. This provides redundancy of the service and prevents A single point of failure.
CNAME records are mainly used for internal jumps of domain names and provide flexibility for server configuration, which is not perceived by users. The domain facebook.github. IO, for example, is a CNAME record. We can usually see the CNAME when we register the CDN.
DNS related technologies used in front-end development
DNS related technologies can be used in front-end performance optimization, mainly to shorten the DNS query time, to shorten the first screen rendering time of front-end pages.
- dns-prefetch
- dns-preconnect
Refer to the link
- what-is-dns
- Introduction to DNS Principles
- DNS chapter dig use detailed explanation
- Dig tool download
- DNS