使用互联网(Internet)时听说过“DNS”这个词吗?DNS代表域名系统(Domain Name System)。在我们继续讨论什么是DNS以及DNS查找如何工作之前,让我们了解DNS中的 D代表什么。
什么是域
您知道 Web URL的格式是http:s//www.domainname.tld。在此示例中,TLD (tld) 指的是顶级域。在网络的早期,TLD是以下之一:
- .com(指商业组织)
- .org(指非营利组织)
- .net(又是商业网站)
- .gov(政府网站)
- .edu(教育)
- .mil(军事用途)和
- .int(国际)
随着购买网站的人数增加,引入了与位置相关的域类型。例如,.asia、.us、.in 和.ca分别指的是亚洲(Asia)、美国、印度(India) 和加拿大(Canada)。很快(Soon),其他几种TLD类型的出现,告诉我们网站的类型。例如,.me指的是个人网站,而.tv指的是视频流媒体网站。增加TLD类别可以根据网站类型对网站进行分类,同时满足消费者日益增长的需求。
在上面的URL示例中(https://www.domainname.tld),https指的是数据传输的方式,www表示它与万维网(World Wide Web)有关。www和TLD之间的任何内容都是网站的域名。
早些时候,人们必须输入www才能访问网站。由于托管服务提供商允许将www.domainname.tld重定向到domainname.tld ,因此您可以在将URL输入浏览器时跳过键入www 。域名的一个例子是“thewindowsclub”。访问域“thewindowsclub”的URL是 https://www.thewindowsclub.com 或 http://thewindowsclub.com。在这里,“ thewindowsclub ”是.com TLD的一部分。然后,可以有子域。对于 www.news.thewindowsclub.com,“ news ”是“ (news)thewindowsclub ”的子域。
当您购买一个域名时,您可以购买一个与不同TLD(TLDs)对应的名称。您可以选择.com、.net、.us或其他TLD——(TLDs –)前提是它尚未被其他人占用。简单地(Simply)购买一个网站将无济于事,因为人们在获得地址之前无法访问它。对于您购买的任何域,您可以创建任意数量的子域并将其用于网站和其他目的。对于您创建的每个域和子域,您需要指定包含您网站内容的服务器地址。如果域或子域指的是某个设备(例如,网络打印机),则需要指定该设备的地址。
互联网(Internet)上的所有域和子域都附加了一个地址。我们称它们为 IP 地址:Internet 协议(Internet Protocol)地址,或者换句话说,与Internet一起工作的地址。只有知道包含其内容的服务器的 IP 地址,才能访问域/子域。
什么是 DNS
你知道互联网(Internet)上有无限的网站。同样(Again),每个网站都可以有自己的许多子域。记住这些网站的 IP 地址是不可能的。这就是您可以用自己的语言输入域名的原因(使用URL格式——在技术上也称为别名)。(alias)有一个系统可以解析域名,这样您就可以连接到您在URL中提到的网站。该系统帮助您查找您在浏览器中输入的域名的 IP 地址,以便浏览器可以连接到网站。该系统简称为域名系统(Domain Name System)或DNS。
域名系统,或俗称的 DNS,是一个分布式数据库,其中包含域名到其 IP 地址的映射(Domain Name System, or DNS as it is popularly known, is a distributed database that contains the mapping of domain names to their IP addresses)。
直到最近,一个名为InternNIC(InternNIC)的非营利组织 负责管理域名及其 IP 地址。当它“以营利为目的”时,它的垄断就结束了,现在有许多公司管理着与域名相关的数据库。尽管数据库由不同的公司维护,但它们以任何DNS 服务(DNS Service)都可以获取任何域的 IP 地址的方式相互连接。
DNS 服务(DNS Service)可帮助您解析在 Web 浏览器中输入的域名。它还有助于在您发送电子邮件或单击活动链接时解析地址。通常,您的Internet 服务提供商会(Internet Service Provider)为您提供DNS 服务(DNS Service)。除了您的ISP,还有一些公司提供公共域名(Domain Name) 服务(Services)。此类公司的示例包括Google、Comodo和OpenDNS。当您单击链接或在 Web 浏览器中输入URL时,将联系(URL)DNS 服务(DNS Service)以解析相关DNS. DNS服务负责扫描域名系统(Domain Name System)数据库并向您提供您希望连接的主机的 IP 地址。
域名和子域可以称为别名(aliases)。拥有包含不同别名地址信息的数据库的服务器称为名称服务器(Name Servers)。域名系统(Domain Name System)中有两种类型的服务器在运行。第一种类型是根服务器(Root Servers)——它们保存有关顶级域(Top Level Domains)(TLD:.com、.net 和 .org 等)的数据。其他类型包含托管您的域和子域的服务器的地址。
示例 1:(Example 1:)在abc.xyz.com的情况下,根服务器(Root Servers)将保存有关xyz是.com的信息。其他一些名称服务器(Server)将包含显示xyz.com地址的数据库条目。由于您还托管abc.xyz.com,因此其地址可以位于保存xyz.com地址的同一(xyz.com)名称(Name)服务器上,也可以位于不同的名称服务器(Server)上。如果您将另一个子域添加到abc.xyz.com,其地址可能再次位于相同或不同的名称服务器上,具体取决于您托管它的位置。上述之间的关系可以建立如下:
xyz
com
abc
xyz.com
qwe
xyz.com
qwe
abc.xyz.com
要建立qwe的地址,域名系统服务(Domain Name System Service)必须解析:
这是域名系统服务(Domain Name System Service)未使用任何缓存的情况。我们将在本文稍后讨论缓存。如上所示,要解析qwe.abc.xyz.com的 DNS,DNS系统需要(DNS)对DNS数据库进行四次扫描。鉴于 URL 不同部分的地址(URL)可以位于不同的名称服务器(Servers)上,这变得很复杂。但是由于互联网(Internet)的速度,您可以在几毫秒内看到页面下载,在最坏的情况下,几秒钟。
DNS 查找的工作原理
到目前为止,您知道有不同的服务器托管包含不同域及其子域的 IP 地址的数据库。您还知道,有一些根服务器保存着托管(Root Servers)顶级域(Top Level Domains)的服务器的 IP 地址。这些根服务器(Root Servers)有助于访问包含保存主域名 IP 地址的数据库的服务器。如果有子域,它们的地址可以在与主域名相同的服务器上,也可以在不同的服务器上。所有这些服务器都可以访问以找出您需要使用的确切URL的 IP 地址。(URL)找出Internet上任何(Internet)URL的IP 地址的过程称为DNS抬头。要了解DNS 查找(DNS Lookup)的工作原理,请看以下示例。
示例 2:(Example 2:)考虑一个由十台计算机组成的网络。每台计算机都有自己的地址,这样在网络中传输的数据包就知道要去哪里。第 11 台计算机托管包含这十台计算机中每台计算机的别名及其 IP 地址的数据库。虽然计算机用户可以使用他们的名字来引用计算机,但数据包需要计算机的 IP 地址才能到达预期的接收者。如果计算机A需要使用计算机B所附的打印机,A会查询第11台计算机的数据库知道B的IP地址,然后找出B所附的打印机的地址。只有在获得打印机的地址后,A将打印命令路由到连接到 B 的打印机。
在这种情况下,会发生以下迭代:
A 联系计算机 11
A 联系 B
A 联系打印机连接到 B
类似的方法用于查找DNS记录。例如,当您单击 http://thewindowsclub.com 时,您的路由器将联系您的默认DNS 服务(DNS Service)进行DNS解析。DNS服务将联系根服务器(Root Servers)并询问包含.com记录的服务器的 IP 地址。此地址将发送回您的DNS服务。DNS服务再次到达包含.com域地址的名称服务器(Server),并要求它提供 http://thewindowsclub.com 的地址。在获得托管 thewindowsclub.com 的服务器的 IP 地址后,您的DNS服务会将 IP 地址返回到您的计算机,然后启动您的浏览器以下载主网页。这意味着您的DNS服务正在发送至少两个请求来接收简单域名的 IP 地址。
下图解释了 DNS 查找的工作原理:(Following is an image that explains how DNS lookup works:)
在上述情况下,如果您要查找 https://news.thewindowsclub.com,您的DNS服务必须额外运行一个请求才能知道其 IP 地址。
由于每次从头开始解析DNS都需要时间,因此许多(DNS)ISP(ISPs)和DNS 服务提供商会(DNS Service Providers)创建包含已解析地址的本地缓存。这些主要是他们在某个时间点已经从根服务器(Root Servers)和其他名称服务器获取的地址。(Servers)在这种情况下,当您发送 URL 请求时,(URL)DNS服务将在其本地DNS缓存中查找URL的解析地址,而不是直接联系根(Root)服务器。如果找到,它会立即将解析发送回您的计算机,否则会继续解析DNS使用上述联系根服务器(Root Servers)和其他名称服务器(Servers)的方法。
某些操作系统也包含您在计算机上常用的地址的本地缓存副本。这也有助于节省使用Internet的时间。稍后我们将在另一篇文章中讨论DNS缓存。
如果您对 DNS 查找的工作方式仍有任何疑问,请告诉我们。(Please let us know if you still have any doubts about how DNS lookup works.)
What Is DNS Lookup And How DNS Lookup Works
Ever hеard about the term “DNЅ” when using the Intеrnet? DNS stands for Domain Name System. Before we go ahead and talk about what is DNS and how DNS lookup works, let us understand what the D in the DNS stands for.
What Is A Domain
You know that the format of a web URL is http:s//www.domainname.tld. In this example, TLD (tld) refers to the top-level domain. In the early days of the web, TLD was one of the following:
- .com (refers to commercial organizations)
- .org (refers to non-profit organizations)
- .net (commercial websites again)
- .gov (government websites)
- .edu (educational)
- .mil (military purposes) and
- .int (international)
With the increase in people purchasing websites, domain types related to locations were introduced. For example, .asia, .us, .in and .ca refer to Asia, US, India and Canada respectively. Soon, several other types of TLD came in that tell us the type of website. For example, .me refers to a personal website whereas a .tv refers to a video streaming website. Increasing the TLD categories made it possible to categorize websites according to their type while catering to the increasing demands of consumers.
In the above example of the URL (https://www.domainname.tld), https refers to the mode of transfer of data, and www says it relates to the World Wide Web. Anything between www and TLD is the domain name of a website.
Earlier, people had to type in www to access a website. Since the hosting service providers allow redirection of www.domainname.tld to domainname.tld, you can skip typing www while entering the URL into the browser. An example of a domain name is “thewindowsclub”. The URL for accessing domain “thewindowsclub” is https://www.thewindowsclub.com or http://thewindowsclub.com. Here, “thewindowsclub” is part of the .com TLD. Then, there can be sub-domains. In the case of www.news.thewindowsclub.com, “news” is the sub-domain of “thewindowsclub”.
When you buy a domain, you get to purchase a name that goes with different TLDs. You can choose .com, .net, .us or other TLDs – provided it is not taken already by someone else. Simply buying a website will not help as people cannot reach it until it has an address. For any domain you purchase, you can create any number of sub-domains and use it for websites and other purposes. For each domain and sub-domain you create, you need to specify the address of servers that contain the content of your website. If the domain or sub-domain refers to some device (for example, a network printer), you need to specify the address of that device.
All the domains and sub-domains on the Internet have an address attached. We call them the IP address: Internet Protocol address or in other words, an address that works with the Internet. You can access a domain/sub-domain only if you know the IP address of servers containing its content.
What Is DNS
You know that there are unlimited websites on the Internet. Again, each website can have its own many sub-domains. Remembering the IP addresses of these websites is simply not possible. This is why you get to enter the domain name in your own language (using the URL format – also called alias in technical terms). There is a system at work that resolves the domain names so that you can connect to the website you mentioned in the URL. This system helps you in finding the IP address of the domain names you entered in your browser so that the browser can connect to the website. This system is called the Domain Name System or DNS for short.
Domain Name System, or DNS as it is popularly known, is a distributed database that contains the mapping of domain names to their IP addresses.
Until recently, a non-profit organization called InternNIC was responsible for managing the domain names and their IP addresses. When it went “for-profit”, its monopoly ended and now there are many companies that manage the databases related to domain names. Though the databases are maintained by different companies, they are interconnected in a manner that any DNS Service can get the IP address of any domain.
A DNS Service helps you in resolving the domain names that you enter in your web browser. It also helps in resolving the addresses when you are sending emails or when you click on active links. In general, your Internet Service Provider gives you a DNS Service. Other than your ISP, there are companies that offer Public Domain Name Services. Examples of such companies include Google, Comodo, and OpenDNS. When you click on a link or enter a URL into your web browser, the DNS Service is contacted for resolving the related DNS. It is the responsibility of the DNS service to scan the Domain Name System database and provide you with the IP address of the host to which you wish to connect.
The domain names and sub-domains can be called aliases. The servers holding a database containing information on the addresses of different aliases are called Name Servers. There are two types of servers operating in the Domain Name System. The first types are the Root Servers – these hold data about Top Level Domains (TLD: .com, .net and .org, etc.). The other types contain the addresses of servers that host your domains and sub-domains.
Example 1: In the case of abc.xyz.com, Root Servers will hold information about xyz being a .com. Some other Name Server will contain database entries showing the address of xyz.com. Since you also are hosting abc.xyz.com, its address can be either on the same Name server holding the address of xyz.com or on a different Name Server. If you add yet another sub-domain to abc.xyz.com, its address may again be on the same or on a different Name server depending upon where you are hosting it. The relation between the above can be established as below:
xyz
com
abc
xyz.com
qwe
xyz.com
qwe
abc.xyz.com
To establish the address of qwe, the Domain Name System Service will have to resolve:
This is a case when the Domain Name System Service is not using any cache. We will talk about caches a little later in this article. The above shows that to resolve the DNS of qwe.abc.xyz.com, the DNS system has to scan the DNS database four times. This becomes complex given that the addresses of different parts of the URL can be on different Name Servers. But due to the speed of the Internet, you can see the page downloading in a matter of few milliseconds and in worst cases, few seconds.
How DNS Lookup Works
By now, you know that there are different servers hosting databases that contain the IP addresses of different domains and their sub-domains. You also know that there are Root Servers that hold the IP address of servers hosting Top Level Domains. These Root Servers help in reaching the servers containing databases that hold the IP address of the main domain name. If there are sub-domains, their address can be on the same servers as of the main domain name or on a different server. All these servers are accessible for finding out the IP address of the exact URL that you need to use. The process of finding out the IP address of any URL on the Internet is known as DNS lookup. To find out how DNS Lookup works, take the following example.
Example 2: Consider a network of ten computers. Each computer has its own address so that data packets traveling in the network know where to go. There is an 11th computer that hosts a database containing the alias names of each of these ten computers and their IP addresses. While the computer users can refer to the computers using their names, the data packets need the IP addresses of the computers so that they can reach the intended recipient. If computer A needs to use the printer attached to computer B, A will check the database on 11th computer to know the IP address of B and then find out the address of printer attached to B. Only after obtaining the address of the printer, A will route the print command to the printer attached to B.
In this case, the following iterations happen:
A contacts Computer11
A contacts B
A contacts printer attached to B
A similar method is used to lookup DNS records. For example, when you click on http://thewindowsclub.com, your router will contact your default DNS Service for DNS resolution. The DNS service will contact Root Servers and ask for the IP address of the server containing .com records. This address is sent back to your DNS service. The DNS service again reaches the Name Server containing addresses of .com domains and asks it for the address of http://thewindowsclub.com. Upon obtaining the IP address of the servers that host thewindowsclub.com, your DNS service will return the IP address to your computer which then fires up your browser to download the main webpage. This means your DNS service is sending at least two requests to receive the IP address of a simple domain name.
Following is an image that explains how DNS lookup works:
In the above case, if you were to look for https://news.thewindowsclub.com, your DNS service had to run a request extra to know its IP address.
Since resolving DNS from scratch every time takes up time, many ISPs and DNS Service Providers create local caches that contain already resolved addresses. These are primarily the addresses they already fetched from Root Servers and other Name Servers at some point in time. In this case, when you send a request for a URL, instead of contacting the Root server directly, the DNS service would look up the resolved address of the URL in its local DNS cache. If found, it would send the resolution back to your computer instantly else would go ahead and resolve the DNS using the above method of contacting Root Servers and other Name Servers.
Some operating systems too, contain a locally cached copy of addresses that you commonly use on your computer. This too, helps in saving time while using the Internet. We will talk about DNS caches in a different article at some later point of time.
Please let us know if you still have any doubts about how DNS lookup works.