Depth analysis of the Java Web technology inside reading notes (b) Analysis of DNS name resolution process

An article "On the Web request" is about how to initiate HTTPa request, it is important for the request to initiate the process of a step - DNSdescribed resolution process is in passing, this article will follow DNSthe resolution process is to analyze the domain name how to parse.

A, DNS name resolution steps

Below is DNSan example of a name resolution, which covers the basic principles and parsing steps.
Write pictures described here
The following DNSanalytical steps to explain, in the form of a command line later to track the DNSresolution process. When users type in the address bar www.baidu.comafter the Enter key and Qiaoxia, DNS began.

Step one: Check if your browser cache cached IP address corresponding to the domain name

After a user visited a Web site through a browser, the browser will automatically cache the domain corresponding IPaddresses, when the user access again, the browser will look for the corresponding IP address from the cache, the cache is not only because there is size limit, but also the time limit (the domain name is cached, by TTLsetting properties), there is a corresponding domain name IPcan not find the. When the browser to find the site corresponding to the domain name from the cache IPaddresses the entire DNSanalytical process is complete, if not found, will be the next step. For IPcaching matter of time, buffer time should not be set too long, too long, if the domain name corresponding to the IPchange, then the user will not be able to properly access the website for some time, if too short, resulting in frequent and resolve domain names.

Step Two: If you do not find in the browser cache IP, it will continue to look for the native system is cached IP

If the first step did not complete the resolution process for domain names, then the browser will go to find out whether the system cache system cache over the corresponding domain name IPaddress, can be understood as the system itself also have the basic ability to name resolution. In the Windowssystem, you can be provided hoststo the domain name manually bind to a file IP, the hostsfile location C:\Windows\System32\drivers\etc\hosts. For the average user, not recommended to manually binding domain and IP, for developers, and through binding domain IP, you can easily switch environment, it can switch from a test environment to a development environment for development and testing. In the XPsystem, hackers often modify his computer hostsfiles, users often access the domain name is bound to his designated IPon in order to achieve a local DNSresolution, leading to these domain name hijacking. In Linuxor Macsystem hostsfile /etc/hosts, the file can be modified to achieve the same purpose.

前两步都是在本机上完成的,所以没有在上面示例图上展示出来,从第三步开始,才正在地向远程DNS服务器发起解析域名的请求。

The third step: initiating a request to the local DNS domain name resolution service system

If you can not resolve the domain name is completed on the machine, the system can only ask a local DNS service system to resolve the local domain name system LDNSdomain name servers are generally in the region, such as campus networks you connect to, then the domain name system in your campus room, if you are connected to Telecom, China mobile or China Unicom's network, a local DNS server in the region, by the respective operators to provide services. For local DNSserver address, Windowssystem commands ipconfigcan be viewed, in Linuxand Macunder the system, use the command directly cat /etc/resolv.confto view the LDNSservice address. LDNSGenerally it caches the results of most of the domain name resolution, of course, by the time the cache expiration time domain control, most of the analytical work here almost over, LDNSresponsible for most of the analytical work.

The fourth step: initiating a DNS request to the root DNS servers

Local DNSdomain name resolver is not yet complete resolution, then the local DNS server will initiate a request to resolve the root name servers.

Step five: root name server returns gTLD DNS server address

Local DNSDNS resolution request to initiate root name servers, root name server returns the generic top-level domain check domain ( Generic top-level domain,gTLD) address, there is a common gTLDs .com, .cn, .org, .eduand so on.

Step Six: initiating a request to resolve the server gTLD

Local DNS server sends a request to the server gTLD.

Step Seven: gTLD server receives the request and returns the Name Server server

gTLDThe server receives the local domain name server initiated the request, and if necessary to resolve domain names, find the domain name corresponding to the Name Serverdomain name server, under normal circumstances, this Name Serverserver is that you register a domain name server, then the service provider's server you register domain names will assume DNS task.

Step eight: Name Server server returns the IP address to a local server

Name ServerFind the corresponding domain name server IPaddress, the IPaddress along with the TTLvalue returned to the local domain name server.

Step 9: local domain name server caches the result of the analysis

Results of the local domain name server caching resolver cache by the time TTLto control the time.

Step 10: analytical results returned to the user

The analysis results returned directly to the user, the system will cache the IPaddress buffer by the time TTLcontrol is, thus, parsing process ends.

Here for DNSparsing step is a brief analysis, particularly later to resolve a domain name resolution process by the command line options.

Two, DNS name resolution process analysis

Before the official start of the parsing process analysis, the first to introduce the concept of a few basic domain name resolution mode. DNS records are divided into A记录, MX记录, CNAME记录, NS记录and TXT记录.

  • A记录: AIt represents Address, for the corresponding domain of IPaddresses, such as will map.baidu.combe assigned to 180.97.34.157the zhidao.baidu.comassigned to 180.149.131.245, Arecording to allow a plurality of DNS IPaddress, but not a domain name to multiple IP addresses.

  • MX记录: MXRepresent Mail Exchage, that is, the mail server in a domain name may be directed to their own Mail Server, such as baidu.comthe domain name Arecord IPaddress 180.97.34.157, if the MXrecord is set 180.97.34.154, that is, [email protected]the mail routing, then DNSsend the message to will 180.97.34.154the server is located, while the normal webrequest still resolves to the AIP address record 180.97.34.157.

  • CNAME记录: CNAMERefers to Canonical Name, that is an alias to resolve the specified domain name can be resolved to another domain name, domain name and other domain names is to specify an alias, the entire resolution process called alias resolution. For example, it will baidu.comresolve to itlemon.cnthe csdn.netresolve to itlemon.cn, it itlemon.cnis baidu.com, and CSDN.netaliases.

  • NS记录: That is designated for a specific domain name DNSserver to resolve.

  • TXT记录: Set to a host name or domain-specific instructions, such as a itlemon.cnset of TXT record is “Lemon的技术笔记”, this TXTrecord is itlemon.cndescribed.

The concept of the above IPaddresses are supposed to help understand. The following by resolving the domain name baidu.com, for example, to further illustrate the domain name resolution process.

Domain name directly view the results, you can command nslookupto view the plus domain name:
Write pictures described here
the above figure Non-authoritative answerrepresents the analytical results from the non-authoritative server, which means that the results from the cache and not fully experience all the parsing process, read from a cache As a result, there is a certain risk that the results, such as the domain name corresponding to IPthe address has been more variable.
This is just a quick analysis result, if you need to see all the parsing process, you can use the digcommand to view the resolution process.
Write pictures described here
On analysis chart DNSparsing process, we can see:
The first step: from local DNSto obtain DNS server to 13a root DNSname servers (.)corresponding host name.
Write pictures described here
Step two: From the 13root name servers in one (here h.root-servers.net) get to the top level com.of the server IP(not shown) and name.
Write pictures described here
The third step: to com.a domain server 192.43.172.30(i.gtld-servers.net)request analysis, it returns the baidu.comserver domain IP(not shown) and name server Baidu has four top-level domain.
Write pictures described here
Step four: to Baidu's top-level domain server 220.181.37.10(ns3.baidu.com)request www.baidu.com, it found that the wwwindividual name, rather than a host alias www.a.shifen.com.
Write pictures described here
Under normal circumstances, DNSresolve to the alias stopped, returned to a specific IPaddress, if you want to see a specific IPaddress, aliases can be further parsed, analytical results are as follows:
Write pictures described here
This is the time to see the final result of the analysis is 180.97.33.107and180.97.33.108. In the process of parsing alias, you can find shifen.comand baidu.comare designated with the same domain name server. The above is a domain name resolution process, the final analytical results and the start of the use of nslookupthe results of the same.

Inside depth analysis of Java Web series study notes articles list:

Depth analysis of the Java Web technology inside reading notes (a) Analysis of a Web request
in-depth analysis Analysis of DNS name resolution process technology insider Java Web reading notes (b)

More dry goods share, welcome attention to my micro-channel public number: Java Mountain (Micro Signal: itlemon)
Here Insert Picture Description

Published 73 original articles · won praise 84 · views 470 000 +

Guess you like

Origin blog.csdn.net/Lammonpeter/article/details/81358387