An article "On the Web request" is about how to initiate
HTTP
a request, it is important for the request to initiate the process of a step -DNS
described resolution process is in passing, this article will followDNS
the resolution process is to analyze the domain name how to parse.
A, DNS name resolution steps
Below is DNS
an example of a name resolution, which covers the basic principles and parsing steps.
The following DNS
analytical steps to explain, in the form of a command line later to track the DNS
resolution process. When users type in the address bar www.baidu.com
after 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 IP
addresses, 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 TTL
setting properties), there is a corresponding domain name IP
can not find the. When the browser to find the site corresponding to the domain name from the cache IP
addresses the entire DNS
analytical process is complete, if not found, will be the next step. For IP
caching matter of time, buffer time should not be set too long, too long, if the domain name corresponding to the IP
change, 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 IP
address, can be understood as the system itself also have the basic ability to name resolution. In the Windows
system, you can be provided hosts
to the domain name manually bind to a file IP
, the hosts
file 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 XP
system, hackers often modify his computer hosts
files, users often access the domain name is bound to his designated IP
on in order to achieve a local DNS
resolution, leading to these domain name hijacking. In Linux
or Mac
system hosts
file /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 LDNS
domain 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 DNS
server address, Windows
system commands ipconfig
can be viewed, in Linux
and Mac
under the system, use the command directly cat /etc/resolv.conf
to view the LDNS
service address. LDNS
Generally 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, LDNS
responsible for most of the analytical work.
The fourth step: initiating a DNS request to the root DNS servers
Local DNS
domain 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 DNS
DNS 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
, .edu
and 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
gTLD
The 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 Server
domain name server, under normal circumstances, this Name Server
server 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 Server
Find the corresponding domain name server IP
address, the IP
address along with the TTL
value 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 TTL
to control the time.
Step 10: analytical results returned to the user
The analysis results returned directly to the user, the system will cache the IP
address buffer by the time TTL
control is, thus, parsing process ends.
Here for
DNS
parsing 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记录
:A
It representsAddress
, for the corresponding domain ofIP
addresses, such as willmap.baidu.com
be assigned to180.97.34.157
thezhidao.baidu.com
assigned to180.149.131.245
,A
recording to allow a plurality of DNSIP
address, but not a domain name to multiple IP addresses. -
MX记录
:MX
RepresentMail Exchage
, that is, the mail server in a domain name may be directed to their ownMail Server
, such asbaidu.com
the domain nameA
recordIP
address180.97.34.157
, if theMX
record is set180.97.34.154
, that is,[email protected]
the mail routing, thenDNS
send the message to will180.97.34.154
the server is located, while the normalweb
request still resolves to theA
IP address record180.97.34.157
. -
CNAME记录
:CNAME
Refers toCanonical 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 willbaidu.com
resolve toitlemon.cn
thecsdn.net
resolve toitlemon.cn
, ititlemon.cn
isbaidu.com
, andCSDN.net
aliases. -
NS记录
: That is designated for a specific domain nameDNS
server to resolve. -
TXT记录
: Set to a host name or domain-specific instructions, such as aitlemon.cn
set of TXT record is“Lemon的技术笔记”
, thisTXT
record isitlemon.cn
described.
The concept of the above
IP
addresses are supposed to help understand. The following by resolving the domain namebaidu.com
, for example, to further illustrate the domain name resolution process.
Domain name directly view the results, you can command nslookup
to view the plus domain name:
the above figure Non-authoritative answer
represents 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 IP
the 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 dig
command to view the resolution process.
On analysis chart DNS
parsing process, we can see:
The first step: from local DNS
to obtain DNS server to 13
a root DNS
name servers (.)
corresponding host name.
Step two: From the 13
root name servers in one (here h.root-servers.net
) get to the top level com.
of the server IP
(not shown) and name.
The third step: to com.
a domain server 192.43.172.30(i.gtld-servers.net)
request analysis, it returns the baidu.com
server domain IP
(not shown) and name server Baidu has four top-level domain.
Step four: to Baidu's top-level domain server 220.181.37.10(ns3.baidu.com)
request www.baidu.com
, it found that the www
individual name, rather than a host alias www.a.shifen.com
.
Under normal circumstances, DNS
resolve to the alias stopped, returned to a specific IP
address, if you want to see a specific IP
address, aliases can be further parsed, analytical results are as follows:
This is the time to see the final result of the analysis is 180.97.33.107
and180.97.33.108
. In the process of parsing alias, you can find shifen.com
and baidu.com
are 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 nslookup
the 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)