CN113992626A - Method, device and storage medium for realizing DNS - Google Patents
Method, device and storage medium for realizing DNS Download PDFInfo
- Publication number
- CN113992626A CN113992626A CN202111232535.8A CN202111232535A CN113992626A CN 113992626 A CN113992626 A CN 113992626A CN 202111232535 A CN202111232535 A CN 202111232535A CN 113992626 A CN113992626 A CN 113992626A
- Authority
- CN
- China
- Prior art keywords
- domain name
- address
- dns
- message
- request message
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Landscapes
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
本申请公开了一种实现DNS的方法、设备、存储介质,该方法包括:可编程交换机接收主机发送的报文,判断所述报文是否为域名系统DNS请求报文;若是,查询芯片硬件表项中是否存在所述DNS请求报文查询的IP地址,所述芯片硬件表项是存储在所述交换机内的;若是,则向所述主机返回所述IP地址;若否,将所述DNS请求报文上传到本地域名服务器进行查询;接收所述本地域名服务器返回的包含所述IP地址的DNS响应报文;对所述DNS响应报文进行解析,根据解析获得的IP地址将所述DNS请求报文包含的域名与所述IP地址的映射关系存储在所述芯片硬件表项中,并将所述IP地址返回到所述主机。
The present application discloses a method, device, and storage medium for implementing DNS. The method includes: a programmable switch receives a message sent by a host, and determines whether the message is a DNS request message of a domain name system; if so, querying a chip hardware table Whether there is an IP address queried by the DNS request message in the item, the chip hardware entry is stored in the switch; if so, return the IP address to the host; if not, use the DNS The request message is uploaded to the local domain name server for query; the DNS response message including the IP address returned by the local domain name server is received; the DNS response message is parsed, and the DNS response message is parsed according to the IP address obtained by the analysis The mapping relationship between the domain name included in the request message and the IP address is stored in the chip hardware entry, and the IP address is returned to the host.
Description
技术领域technical field
本申请涉及域名解析领域,尤其涉及一种实现DNS的方法、设备、存储介质。The present application relates to the field of domain name resolution, and in particular, to a method, device and storage medium for implementing DNS.
背景技术Background technique
IP地址标识着计算机互联网中的终端用户。终端用户会用域名访问来替代IP地址。为了实现域名的访问,两者之间需要域名解析。IP addresses identify end users in the computer Internet. End users will use domain name access instead of IP address. In order to achieve domain name access, domain name resolution is required between the two.
域名系统(Domain Name System,DNS)是连接整个互联网应用层和网络层的纽带,主要功能是实现IP地址与域名间的转换,以定位和标识互联网的资源,是众多网络应用(网页浏览、电子邮件等)正常运转的基础。Domain Name System (DNS) is the link connecting the entire Internet application layer and the network layer. Its main function is to realize the conversion between IP addresses and domain names to locate and identify Internet resources. mail, etc.) to function properly.
但现有的域名解析时往往由于网络带宽小、用户访问量大,而出现访问网站的响应速度慢等问题,影响用户体验。However, in the existing domain name resolution, problems such as slow response speed of visiting websites often occur due to the small network bandwidth and the large number of user visits, which affects the user experience.
发明内容SUMMARY OF THE INVENTION
本申请提供了一种实现DNS方法,解决了由于用户访问量大导致访问网站的响应速度慢的技术问题。The present application provides a method for implementing DNS, which solves the technical problem of slow response speed of visiting websites due to a large number of user visits.
一种实现域名系统DNS加速方法,包括:A method for realizing DNS acceleration of a domain name system, comprising:
可编程交换机接收主机发送的报文,判断所述报文是否为域名系统DNS请求报文;The programmable switch receives the message sent by the host, and determines whether the message is a DNS request message of the domain name system;
若是,查询芯片硬件表项中是否存在所述DNS请求报文查询的IP地址,所述芯片硬件表项是存储在所述交换机内的;If yes, query whether the IP address queried by the DNS request message exists in the chip hardware table entry, and the chip hardware table entry is stored in the switch;
若是,则向所述主机返回所述IP地址;If so, return the IP address to the host;
若否,将所述DNS请求报文上传到本地域名服务器进行查询;If not, upload the DNS request message to the local domain name server for query;
接收所述本地域名服务器返回的包含所述IP地址的DNS响应报文;receiving a DNS response message including the IP address returned by the local domain name server;
对所述DNS响应报文进行解析,根据解析获得的IP地址将所述DNS请求报文包含的域名与所述IP地址的映射关系存储在所述芯片硬件表项中,并将所述IP地址返回到所述主机。The DNS response message is parsed, and the mapping relationship between the domain name included in the DNS request message and the IP address is stored in the chip hardware entry according to the IP address obtained by the analysis, and the IP address is stored in the chip hardware table entry. Return to the host.
在本申请的一种实施例中,所述判断所述报文是否为域名系统DNS请求报文,具体包括:从可编程交换机的端口接收主机发送的报文;对所述报文进行解析;将解析后的报文传送到逻辑处理单元进行定义规则的匹配;将能够与定义规则匹配的报文识别为域名系统DNS请求报文。In an embodiment of the present application, the judging whether the message is a domain name system DNS request message specifically includes: receiving a message sent by a host from a port of a programmable switch; parsing the message; The parsed message is sent to the logical processing unit to match the defined rules; the message that can match the defined rule is identified as a DNS request message of the domain name system.
在本申请的一种实施例中,所述查询芯片硬件表项中是否存在与所述DNS请求报文查询的IP地址对应的IP地址,具体包括:在所述芯片硬件表项中查询是否存在与所述DNS请求报文中包含的DNS域名一致的DNS域名;若是,查询所述DNS域名对应的IP地址;确定所述对应的IP地址的状态有效;向主机返回所述IP地址。In an embodiment of the present application, the querying whether there is an IP address corresponding to the IP address queried by the DNS request message in the chip hardware entry specifically includes: querying whether there is an IP address in the chip hardware entry A DNS domain name consistent with the DNS domain name included in the DNS request message; if so, query the IP address corresponding to the DNS domain name; determine that the state of the corresponding IP address is valid; return the IP address to the host.
在本申请的一种实施例中,所述将所述DNS请求报文上传到本地DNS服务器进行查询,具体包括:若本地域名服务器在本地查询到了所述DNS请求报文包含的域名对应的IP地址,则向可编程服务器回复携带所述IP地址的报文;若所述本地域名服务器未在本地查询到域名对应的IP地址,则向其上一级域名服务器查询IP地址;若所述本地域名服务器的上一级未查询到对应的IP地址,则继续向所述本地域名服务器的上一级域名服务器的上一级域名服务器进行查询,执行递归查询,直到查询到所述域名对应的IP地址;当查询到与所述域名对应的IP地址时,通过域名服务器逐级递归传递回所述本地域名服务器;通过可编程交换机接收所述本地域名服务器查询到的对应所述域名的IP报文,并将所述域名对应的IP地址存储到所述芯片硬件表项中。In an embodiment of the present application, uploading the DNS request message to a local DNS server for query specifically includes: if the local domain name server locally queries the IP corresponding to the domain name included in the DNS request message address, reply the message carrying the IP address to the programmable server; if the local domain name server does not find the IP address corresponding to the domain name locally, query the IP address from the upper-level domain name server; If the upper-level domain name server does not query the corresponding IP address, then continue to query the upper-level domain name server of the upper-level domain name server of the local domain name server, and perform recursive query until the IP corresponding to the domain name is queried. address; when the IP address corresponding to the domain name is queried, pass it back to the local domain name server recursively through the domain name server level by level; receive the IP message corresponding to the domain name queried by the local domain name server through the programmable switch , and store the IP address corresponding to the domain name in the chip hardware entry.
在本申请的一种实施例中,所述对所述报文进行解析,具体包括:解析得到所述报文中的源mac地址和源IP地址,以确定发送所述报文的主机;解析得到所述报文中的vlan信息,以确定所述报文的转发路径;解析得到所述报文中的DNS数据段,以确定所述报文为DNS报文;解析得到所述DNS报文中的标志位,以确定所述DNS报文是DNS请求报文还是DNS响应报文;解析得到所述DNS报文中的标识位,以辅助可编程交换机确定DNS请求报文与DNS响应报文的一致性。In an embodiment of the present application, the parsing of the packet specifically includes: parsing to obtain the source mac address and source IP address in the packet, so as to determine the host sending the packet; parsing Obtain the vlan information in the message to determine the forwarding path of the message; parse and obtain the DNS data segment in the message to determine that the message is a DNS message; parse and obtain the DNS message The flag bit in to determine whether the DNS message is a DNS request message or a DNS response message; Parse to obtain the identification bit in the DNS message, to assist the programmable switch to determine the DNS request message and the DNS response message consistency.
在本申请的一种实施例中,在将所述DNS请求报文包含的域名与所述IP地址的映射关系存储在所述芯片硬件表项中之后,所述方法还包括:若域名服务器中存储的域名和IP地址的映射关系更改,则对所述芯片硬件表项中的IP地址进行刷新。In an embodiment of the present application, after storing the mapping relationship between the domain name included in the DNS request packet and the IP address in the chip hardware entry, the method further includes: if the domain name server When the stored mapping relationship between the domain name and the IP address is changed, the IP address in the chip hardware table entry is refreshed.
在本申请的一种实施例中,当主机接收到的DNS响应报文中包含的IP地址无效时,向可编程交换机发送IP地址无效的信号;基于用户的刷新操作,由主机重新向可编程交换机发送DNS请求报文;可编程交换机接收到所述DNS请求后向本地域名服务器转发所述DNS请求报文。In an embodiment of the present application, when the IP address included in the DNS response message received by the host is invalid, a signal indicating that the IP address is invalid is sent to the programmable switch; The switch sends the DNS request message; after receiving the DNS request, the programmable switch forwards the DNS request message to the local domain name server.
在本申请的一种实施例中,在接收主机发送的报文之前,所述方法还包括:在可编程交换机上运行DNS server程序;根据运行的所述DNS server程序,将生成的sr.conf默认为主配置文件,将生成的root.z文件用于配置相关记录。In an embodiment of the present application, before receiving the message sent by the host, the method further includes: running a DNS server program on the programmable switch; The default is the main configuration file, and the generated root.z file is used to configure related records.
本申请实施例还提供了一种实现域名系统DNS的设备,包括:The embodiment of the present application also provides a device for implementing the domain name system DNS, including:
至少一个处理器;以及,at least one processor; and,
与所述至少一个处理器通信连接的存储器;其中,a memory communicatively coupled to the at least one processor; wherein,
所述存储器存储有可被所述至少一个处理器执行的指令,所述指令被所述至少一个处理器执行,以使所述至少一个处理器能够:The memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to:
可编程交换机接收主机发送的报文,判断所述报文是否为域名系统DNS请求报文;The programmable switch receives the message sent by the host, and determines whether the message is a DNS request message of the domain name system;
若是,查询芯片硬件表项中是否存在所述DNS请求报文查询的IP地址,所述芯片硬件表项是存储在所述交换机内的;If yes, query whether the IP address queried by the DNS request message exists in the chip hardware table entry, and the chip hardware table entry is stored in the switch;
若是,则向所述主机返回所述IP地址;If so, return the IP address to the host;
若否,将所述DNS请求报文上传到本地域名服务器进行查询;If not, upload the DNS request message to the local domain name server for query;
接收所述本地域名服务器返回的包含所述IP地址的DNS响应报文;receiving a DNS response message including the IP address returned by the local domain name server;
对所述DNS响应报文进行解析,根据解析获得的IP地址将所述DNS请求报文包含的域名与所述IP地址的映射关系存储在所述芯片硬件表项中,并将所述IP地址返回到所述主机。The DNS response message is parsed, and the mapping relationship between the domain name included in the DNS request message and the IP address is stored in the chip hardware entry according to the IP address obtained by the analysis, and the IP address is stored in the chip hardware table entry. Return to the host.
本申请实施例还提供了一种非易失性存储介质,存储有计算机可执行指令,其特征在于,所述计算机可执行指令设置为:Embodiments of the present application further provide a non-volatile storage medium storing computer-executable instructions, wherein the computer-executable instructions are set to:
可编程交换机接收主机发送的报文,判断所述报文是否为域名系统DNS请求报文;The programmable switch receives the message sent by the host, and determines whether the message is a DNS request message of the domain name system;
若是,查询芯片硬件表项中是否存在所述DNS请求报文查询的IP地址,所述芯片硬件表项是存储在所述交换机内的;If yes, query whether the IP address queried by the DNS request message exists in the chip hardware table entry, and the chip hardware table entry is stored in the switch;
若是,则向所述主机返回所述IP地址;If so, return the IP address to the host;
若否,将所述DNS请求报文上传到本地域名服务器进行查询;If not, upload the DNS request message to the local domain name server for query;
接收所述本地域名服务器返回的包含所述IP地址的DNS响应报文;receiving a DNS response message including the IP address returned by the local domain name server;
对所述DNS响应报文进行解析,根据解析获得的IP地址将所述DNS请求报文包含的域名与所述IP地址的映射关系存储在所述芯片硬件表项中,并将所述IP地址返回到所述主机。The DNS response message is parsed, and the mapping relationship between the domain name included in the DNS request message and the IP address is stored in the chip hardware entry according to the IP address obtained by the analysis, and the IP address is stored in the chip hardware table entry. Return to the host.
本申请提供了一种实现DNS方法,至少包括以下有益效果:当终端用户访问域名时,通过将可编程交换机作为作为本地DNS服务器,能够加速主机对应域名的查询,有效避免网络带宽小、用户访问量大、网点分布不均等问题,提高用户访问网站的响应速度。通过对第一次查询其IP地址的域名进行记录,实现了一次学习,在之后的相同域名的DNS请求即可实现多次自动回复,而无需经过多级的域名服务器进行查询,加速了DNS的查询。通过可编程交换机硬件级别的DNS节点访问加速,加速DNS域名解析。同时实现轻量级的DNS服务器部署,满足小型网络的DNS服务器部署要求,节省用户成本。The present application provides a method for implementing DNS, which at least includes the following beneficial effects: when a terminal user accesses a domain name, by using a programmable switch as a local DNS server, the query of the domain name corresponding to the host can be accelerated, and the network bandwidth is small and user access is effectively avoided. It can improve the response speed of users visiting the website. By recording the domain name whose IP address is queried for the first time, a learning is realized, and subsequent DNS requests of the same domain name can be automatically replied multiple times without going through multi-level domain name servers for query, which speeds up the DNS process. Inquire. Accelerates DNS domain name resolution through the acceleration of DNS node access at the hardware level of programmable switches. At the same time, it implements lightweight DNS server deployment to meet the DNS server deployment requirements of small networks and save user costs.
附图说明Description of drawings
此处所说明的附图用来提供对本申请的进一步理解,构成本申请的一部分,本申请的示意性实施例及其说明用于解释本申请,并不构成对本申请的不当限定。在附图中:The drawings described herein are used to provide further understanding of the present application and constitute a part of the present application. The schematic embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation of the present application. In the attached image:
图1为本申请实施例提供的一种实现DNS方法的步骤示意图;1 is a schematic diagram of steps for implementing a DNS method provided by an embodiment of the present application;
图2为本申请实施例提供的可编程交换机实现DNS系统示意图;2 is a schematic diagram of a programmable switch implementing a DNS system provided by an embodiment of the present application;
图3为本申请实施例提供的一种实现DNS的设备组成结构示意图。FIG. 3 is a schematic structural diagram of a device for implementing DNS according to an embodiment of the present application.
具体实施方式Detailed ways
为了使本申请的目的、技术方案和优点更加清楚,下面将结合本申请具体实施例对本申请进行清楚、完整的描述。显然,所描述的实施例仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to make the objectives, technical solutions and advantages of the present application clearer, the present application will be described clearly and completely below with reference to the specific embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
网络之间互连的协议(Internet Protocol,IP)地址标识着计算机互联网中的终端用户。终端用户会用域名访问来替代IP地址。为了实现域名的访问,两者之间需要域名解析。由于域名系统的设计是传输控制协议/网络之间互连的协议(Transmission ControlProtocol/Internet Protocol,TCP/IP)应用程序的分布式数据库。那么访问域名时,如果在主机本地域名系统(Domain Name System,DNS)解析器的缓存记录中拿不到对应的IP地址后,就会递归往下一个DNS递归服务器进行查询,最终拿到域名对应的IP地址。The Internet Protocol (IP) addresses interconnected between networks identify end users in the computer Internet. End users will use domain name access instead of IP address. In order to achieve domain name access, domain name resolution is required between the two. Because the design of the domain name system is a distributed database of Transmission Control Protocol/Internet Protocol (Transmission Control Protocol/Internet Protocol, TCP/IP) applications. Then when accessing a domain name, if the corresponding IP address cannot be obtained in the cache record of the host's local Domain Name System (DNS) resolver, it will recursively go to the next DNS recursive server to query, and finally get the corresponding domain name IP address.
域名系统(Domain Name System,DNS)是连接整个互联网应用层和网络层的纽带,主要功能是实现IP地址与域名间的转换,以定位和标识互联网的资源,是众多网络应用(网页浏览、电子邮件等)正常运转的基础。Domain Name System (DNS) is the link connecting the entire Internet application layer and the network layer. Its main function is to realize the conversion between IP addresses and domain names to locate and identify Internet resources. mail, etc.) to function properly.
但现有的域名解析时往往由于网络带宽小、用户访问量大,而出现访问网站的响应速度慢等问题,影响用户体验。However, in the existing domain name resolution, problems such as slow response speed of visiting websites often occur due to the small network bandwidth and the large number of user visits, which affects the user experience.
本申请提供的一种实现DNS方法,当终端用户访问域名时,通过将可编程交换机作为作为本地DNS服务器,能够加速主机对应域名的查询,有效避免网络带宽小、用户访问量大、网点分布不均等问题,提高用户访问网站的响应速度。下面进行具体说明。A method for implementing DNS provided by this application, when a terminal user accesses a domain name, by using a programmable switch as a local DNS server, the query of the corresponding domain name of the host can be accelerated, and the network bandwidth is small, the user access volume is large, and the distribution of the network points is not effectively avoided. Equalize the problem and improve the response speed of users visiting the website. A specific description will be given below.
图1为本申请实施例提供的一种实现DNS方法的步骤示意图,可以包括以下步骤:1 is a schematic diagram of steps for implementing a DNS method provided by an embodiment of the present application, which may include the following steps:
S101:接收主机发送的报文,判断报文是否为域名系统DNS请求报文。S101: Receive a message sent by the host, and determine whether the message is a DNS request message of the domain name system.
主机在访问网络的过程中,要查询访问的网络对应的IP地址,首先要由主机向可编程交换机发送DNS请求报文,当可编程交换机查询到对应的IP地址时,生成DNS响应报文返回主机。如图2所示,DNS查询可通过建立的可编程交换机的系统进行加速。可编程交换机接收到来自主机的DNS请求报文后,通过CPU对该报文进行处理,若在可编程交换机的可编程芯片中查询到对应的IP地址,则向主机回复DNS响应报文,若未在可编程芯片P4中查询到,则将DNS请求报文转发到上一级DNS服务器进行查询。当上一级DNS服务器查询到对应的IP地址时,向可编程交换机返回DNS响应报文。In the process of accessing the network, the host needs to query the IP address corresponding to the accessed network. First, the host sends a DNS request message to the programmable switch. When the programmable switch queries the corresponding IP address, it generates a DNS response message and returns it. host. As shown in Figure 2, DNS queries can be accelerated through a system of established programmable switches. After the programmable switch receives the DNS request message from the host, it processes the message through the CPU. If the corresponding IP address is queried in the programmable chip of the programmable switch, it will reply the DNS response message to the host. If it is not queried in the programmable chip P4, the DNS request message is forwarded to the upper-level DNS server for query. When the upper-level DNS server finds the corresponding IP address, it returns a DNS response message to the programmable switch.
在本申请的一种实施例中,在接收主机发送的报文之前,在可编程交换机上运行DNS服务器(DNS server)程序;根据运行的DNS server程序,将生成的sr.conf默认为主配置文件,将生成的root.z文件用于配置相关记录。DNS server是一个能够支持主机通过可编程交换机查找域名对应的IP地址的应用程序。In an embodiment of the present application, before receiving the message sent by the host, run a DNS server (DNS server) program on the programmable switch; according to the running DNS server program, the generated sr.conf is configured as the main configuration by default file, the generated root.z file is used to configure related records. DNS server is an application program that can support the host to find the IP address corresponding to the domain name through the programmable switch.
具体地,为了能够在可编程交换机上良好的运行DNS server程序,可编程交换机上的操作系统可为Linux操作系统,安装的软件为dnspod-sr,以支持DNS server程序在可编程交换机上运行。dnspod-sr是一个运行在Linux操作系统上的高性能的递归DNS服务器软件,具备高性能、高负载、易扩展的优势,其特性稳定,有效降低解析的失败率,能够主动刷新缓存,且响应速度快。Specifically, in order to run the DNS server program well on the programmable switch, the operating system on the programmable switch can be a Linux operating system, and the installed software is dnspod-sr to support the DNS server program running on the programmable switch. dnspod-sr is a high-performance recursive DNS server software running on the Linux operating system. It has the advantages of high performance, high load, and easy expansion. Its characteristics are stable, which can effectively reduce the failure rate of parsing. It can actively refresh the cache and respond to high speed.
在解开的根目录会有三个配置文件:records.z、root.z、sr.conf,sr.conf默认为主配置文件,启动时自动会读取该配置文件的内容。root.z配置文件用于配置相关记录。There will be three configuration files in the unpacked root directory: records.z, root.z, sr.conf, sr.conf is the main configuration file by default, and the content of the configuration file will be automatically read at startup. The root.z configuration file is used to configure related records.
在本申请的一种实施例中,主机发送的报文从可编程交换机的端口进入,然后通过可编程交换机中可编程芯片对报文进行解析。报文一般包含主机的源mac地址、源IP地址、vlan信息以及DNS数据段等。解析得到报文中的源mac地址和源IP地址,以确定发送报文的主机;解析得到报文中的vlan信息,以确定报文的转发路径;解析得到报文中的DNS数据段,以确定报文为DNS报文,在数据层面上识别了DNS流量;解析得到DNS报文中的标志位,以确定DNS报文是DNS请求报文还是DNS响应报文;解析得到DNS报文中的标识位,以辅助可编程交换机确定DNS请求报文与DNS响应报文的一致性。In an embodiment of the present application, the packet sent by the host enters through the port of the programmable switch, and then the packet is parsed by the programmable chip in the programmable switch. The packet generally includes the host's source mac address, source IP address, vlan information, and DNS data segments. The source mac address and source IP address in the packet are obtained through parsing to determine the host sending the packet; the vlan information in the packet is obtained through parsing to determine the forwarding path of the packet; the DNS data segment in the packet is obtained through parsing to determine the forwarding path of the packet. It is determined that the message is a DNS message, and the DNS traffic is identified at the data level; the flag bits in the DNS message are obtained by parsing to determine whether the DNS message is a DNS request message or a DNS response message; The flag is used to assist the programmable switch in determining the consistency between the DNS request message and the DNS response message.
将解析后的报文传送到逻辑处理单元进行定义规则的匹配,通过解析获得的数据段内容,能够根据定义规则匹配识别出该数据段内容为DNS请求数据,那么接下来便对该报文执行相应的处理。The parsed message is sent to the logic processing unit for matching of defined rules. The content of the data segment obtained by parsing can be identified as DNS request data according to the defined rule matching, and then the message is executed next. deal with accordingly.
S102:若是,查询芯片硬件表项中是否存在所述DNS请求报文查询的IP地址,所述芯片硬件表项是存储在所述交换机内的。S102: If yes, query whether the IP address queried by the DNS request message exists in the chip hardware entry, where the chip hardware entry is stored in the switch.
在本申请的一种实施例中,当可编程交换机接收并识别出主机发送来的报文是DNS请求报文,首先在可编程交换机中的芯片硬件表项中查询是否存在与该DNS请求报文中包含的DNS域名一致的DNS域名,芯片硬件表项的格式如下表所示。In an embodiment of the present application, when the programmable switch receives and recognizes that the message sent by the host is a DNS request message, it firstly queries the chip hardware entry in the programmable switch whether there is a message related to the DNS request message. The DNS domain name included in this article is the same as the DNS domain name, and the format of the chip hardware table entry is shown in the following table.
S103:若是,则向主机返回IP地址。S103: If yes, return the IP address to the host.
若存在,在芯片硬件表项中查询该DNS域名是否有对应的IP地址;若是,查询对应的IP地址的状态是否有效;若是,向主机返回IP地址。If it exists, query whether the DNS domain name has a corresponding IP address in the chip hardware table entry; if so, query whether the status of the corresponding IP address is valid; if so, return the IP address to the host.
S104:若否,将DNS请求报文上传到本地域名服务器进行查询。S104: If no, upload the DNS request message to the local domain name server for query.
在本申请的一种实施例中,当可编程交换机没有在其本地查询到DNS请求报文对应的IP地址,则根据TCP/IP参数中设置的首选DNS服务器(一般为本地域名服务器),向本地域名服务器转发DNS请求报文,此本地域名服务器收到查询请求时,如果要检测到查询的域名包含在本地域名服务器在本地配置区域资源中,也就是说,若本地域名服务器在本地查询到了DNS请求报文包含的域名对应的IP地址,则向可编程服务器回复解析结果,即携带IP地址的报文,完成域名解析。如果域名不在本地域名服务器进行解析,但是在本地域名服务器缓存了域名与IP地址的映射关系,则完成域名解析。In an embodiment of the present application, when the programmable switch does not locally query the IP address corresponding to the DNS request message, then according to the preferred DNS server (usually the local domain name server) set in the TCP/IP parameters, The local domain name server forwards the DNS request message. When the local domain name server receives the query request, if it detects that the domain name to be queried is contained in the local domain name server's local configuration area resources, that is, if the local domain name server finds the query locally The IP address corresponding to the domain name contained in the DNS request message will reply the resolution result to the programmable server, that is, the message carrying the IP address, to complete the domain name resolution. If the domain name is not resolved on the local domain name server, but the mapping relationship between the domain name and the IP address is cached on the local domain name server, the domain name resolution is completed.
若本地域名服务器未在本地查询到域名对应的IP地址,则向其上一级域名服务器查询IP地址;若本地域名服务器的上一级未查询到对应的IP地址,则继续向本地域名服务器的上一级域名服务器的上一级域名服务器进行查询,执行递归查询,直到查询到域名对应的IP地址;当查询到与域名对应的IP地址时,通过域名服务器逐级递归传递回本地域名服务器;通过可编程交换机接收本地域名服务器查询到的对应域名的IP报文,并将域名对应的IP地址存储到芯片硬件表项中。If the local domain name server does not query the IP address corresponding to the domain name locally, it will query the IP address of the upper-level domain name server; The upper-level domain name server of the upper-level domain name server performs a query, and performs a recursive query until the IP address corresponding to the domain name is queried; when the IP address corresponding to the domain name is queried, it is recursively transmitted back to the local domain name server through the domain name server level by level; The programmable switch receives the IP packet corresponding to the domain name queried by the local domain name server, and stores the IP address corresponding to the domain name in the chip hardware table entry.
具体地,如果本地域名服务器和缓存解析都失败,则根据本地域名服务器的设置进行查询,该本地域名服务器就会把DNS请求报文转发至上一级域名服务器,由上一级服务器进行解析,本地域名服务器的上一级域名服务器一般为根域名服务器,根域名服务器如果不能解析,那么由根域名服务器再把转请求转至其上一级域名服务器,根域名服务器的上一级域名服务器一般为顶级域名服务器,以此进行递归查询。当查询到与域名对应的IP地址时,通过域名服务器逐级递归传递回本地域名服务器,例如若在顶级域名服务器查询到了对应的IP地址,便由顶级域名服务器传递回到根域名服务器,再由根域名服务器传递回本地域名服务器,再由本地域名服务器传递回可编程交换机,再由可编程交换机返回到主机。Specifically, if both the local domain name server and the cache resolution fail, the query is performed according to the settings of the local domain name server, and the local domain name server will forward the DNS request message to the upper-level domain name server, which will be parsed by the upper-level server. The upper-level domain name server of the domain name server is generally the root domain name server. If the root domain name server cannot be resolved, the root domain name server will then forward the forwarding request to its upper-level domain name server. The upper-level domain name server of the root domain name server is generally Top-level domain name servers for recursive queries. When the IP address corresponding to the domain name is queried, it is recursively passed back to the local domain name server through the domain name server. The root domain name server is passed back to the local domain name server, which is then passed back to the programmable switch by the local domain name server, and then returned to the host by the programmable switch.
S105:接收本地域名服务器返回的包含对应IP地址的DNS响应报文。S105: Receive a DNS response message including a corresponding IP address returned by the local domain name server.
当本地域名服务器发送DNS响应报文时,通过可编程交换机接收返回的包含对应IP地址的DNS响应报文。When the local domain name server sends a DNS response message, the programmable switch receives the returned DNS response message containing the corresponding IP address.
S106:对DNS响应报文进行解析,根据解析获得的IP地址将DNS请求报文包含的域名与IP地址的映射关系存储在芯片硬件表项中,并将IP地址返回到主机。S106: Parse the DNS response message, store the mapping relationship between the domain name and the IP address contained in the DNS request message in the chip hardware table entry according to the IP address obtained by the parsing, and return the IP address to the host.
当可编程交换机接收本地域名服务器查询到的对应域名的IP报文时,对该报文解析并将域名对应的IP地址存储到芯片硬件表项中。通过将域名与IP地址的映射关系存入到芯片硬件表项中,实现了一次学习,多次自动回复该域名请求的IP地址,实现了DNS的加速查询。When the programmable switch receives the IP packet corresponding to the domain name queried by the local domain name server, it parses the packet and stores the IP address corresponding to the domain name in the chip hardware table entry. By storing the mapping relationship between the domain name and the IP address in the chip hardware table entry, one-time learning is realized, and the IP address requested by the domain name is automatically replied many times, thus realizing the accelerated query of DNS.
在本申请的一种实施例中,在将DNS请求报文包含的域名与IP地址的映射关系存储在芯片硬件表项中之后,为了防止缓存的映射关系失效,当域名服务器中存储的域名和IP地址的映射关系失效或更改时,则对芯片硬件表项中的IP地址进行刷新。In an embodiment of the present application, after the mapping relationship between the domain name and the IP address contained in the DNS request message is stored in the chip hardware table entry, in order to prevent the cached mapping relationship from invalidating, when the domain name stored in the domain name server and the IP address are stored in the When the mapping relationship of the IP address is invalid or changed, the IP address in the hardware table entry of the chip is refreshed.
在本申请的一种实施例中,可编程交换机根据芯片硬件表项中存储的映射关系向主机返回对应的IP地址,当主机接收到的DNS响应报文中包含的IP地址无效时,在主机界面咋看不到访问的网址的页面信息,那么就说明主机接受到的IP地址是无效的。主机此时可向可编程交换机发送IP地址无效的信号,告知可编程交换机中存储的IP地址是无效的。未访问到对应网址则用户会点击界面中的刷新按钮,此时主机会再次向可编程交换机发送DNS请求报文;可编程交换机接收到所述DNS请求后向本地域名服务器转发该DNS请求报文,由本地域名服务器去查询该网址对应的IP地址,然后通过递归的方式将IP地址返回主机。In an embodiment of the present application, the programmable switch returns the corresponding IP address to the host according to the mapping relationship stored in the chip hardware entry. When the IP address included in the DNS response packet received by the host is invalid, the host If the interface cannot see the page information of the visited website, it means that the IP address received by the host is invalid. At this time, the host can send a signal that the IP address is invalid to the programmable switch, to inform the programmable switch that the IP address stored in the switch is invalid. If the corresponding website is not accessed, the user will click the refresh button in the interface, and the host will send the DNS request message to the programmable switch again; the programmable switch will forward the DNS request message to the local domain name server after receiving the DNS request. , the local domain name server will query the IP address corresponding to the URL, and then return the IP address to the host in a recursive way.
以上为本申请实施例提供的一种实现DNS方法,基于同样的发明思路,本申请实施例还提供了相应的一种实现DNS的设备,如图3所示。A method for implementing DNS provided by an embodiment of the present application is provided above. Based on the same inventive idea, an embodiment of the present application also provides a corresponding device for implementing DNS, as shown in FIG. 3 .
本实施例提供了一种实现DNS的设备,包括:This embodiment provides a device for implementing DNS, including:
至少一个处理器;以及,at least one processor; and,
与至少一个处理器通信连接的存储器;其中,a memory communicatively coupled to the at least one processor; wherein,
存储器存储有可被至少一个处理器执行的指令,指令被至少一个处理器执行,以使至少一个处理器能够:The memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to:
可编程交换机接收主机发送的报文,判断报文是否为域名系统DNS请求报文;The programmable switch receives the message sent by the host, and determines whether the message is a DNS request message of the domain name system;
若是,查询芯片硬件表项中是否存在DNS请求报文查询的IP地址,芯片硬件表项是存储在交换机内的;If yes, query whether there is an IP address queried by the DNS request message in the chip hardware table entry. The chip hardware table entry is stored in the switch;
若是,则向主机返回IP地址;If so, return the IP address to the host;
若否,将DNS请求报文上传到本地域名服务器进行查询;If not, upload the DNS request message to the local domain name server for query;
接收本地域名服务器返回的包含IP地址的DNS响应报文;Receive the DNS response message containing the IP address returned by the local domain name server;
对DNS响应报文进行解析,根据解析获得的IP地址将DNS请求报文包含的域名与IP地址的映射关系存储在芯片硬件表项中,并将IP地址返回到主机。The DNS response message is parsed, and the mapping relationship between the domain name and the IP address contained in the DNS request message is stored in the chip hardware table entry according to the IP address obtained by the resolution, and the IP address is returned to the host.
基于同样的思路,本申请的一些实施例还提供了上述方法对应的介质。Based on the same idea, some embodiments of the present application also provide a medium corresponding to the above method.
本申请的一些实施例提供的一种实现DNS的非易失性存储介质,存储有计算机可执行指令,计算机可执行指令设置为:Some embodiments of the present application provide a non-volatile storage medium for implementing DNS, which stores computer-executable instructions, and the computer-executable instructions are set to:
可编程交换机接收主机发送的报文,判断报文是否为域名系统DNS请求报文;The programmable switch receives the message sent by the host, and determines whether the message is a DNS request message of the domain name system;
若是,查询芯片硬件表项中是否存在DNS请求报文查询的IP地址,芯片硬件表项是存储在交换机内的;If yes, query whether there is an IP address queried by the DNS request message in the chip hardware table entry. The chip hardware table entry is stored in the switch;
若是,则向主机返回IP地址;If so, return the IP address to the host;
若否,将DNS请求报文上传到本地域名服务器进行查询;If not, upload the DNS request message to the local domain name server for query;
接收本地域名服务器返回的包含IP地址的DNS响应报文;Receive the DNS response message containing the IP address returned by the local domain name server;
对DNS响应报文进行解析,根据解析获得的IP地址将DNS请求报文包含的域名与IP地址的映射关系存储在芯片硬件表项中,并将IP地址返回到主机。The DNS response message is parsed, and the mapping relationship between the domain name and the IP address contained in the DNS request message is stored in the chip hardware table entry according to the IP address obtained by the resolution, and the IP address is returned to the host.
本申请提供了一种实现DNS方法,至少包括以下有益效果:当终端用户访问域名时,通过将可编程交换机作为作为本地DNS服务器,能够加速主机对应域名的查询,有效避免网络带宽小、用户访问量大、网点分布不均等问题,提高用户访问网站的响应速度。The present application provides a method for implementing DNS, which at least includes the following beneficial effects: when a terminal user accesses a domain name, by using a programmable switch as a local DNS server, the query of the domain name corresponding to the host can be accelerated, and the network bandwidth is small and user access is effectively avoided. It can improve the response speed of users visiting the website.
本申请中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于方法和介质实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。Each embodiment in this application is described in a progressive manner, and the same and similar parts between the various embodiments may be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the method and medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and reference may be made to some descriptions of the method embodiments for related parts.
本申请实施例提供的方法和介质与方法是一一对应的,因此,方法和介质也具有与其对应的方法类似的有益技术效果,由于上面已经对方法的有益技术效果进行了详细说明,因此,这里不再赘述方法和介质的有益技术效果。The methods and media provided in the embodiments of the present application are in a one-to-one correspondence with the methods. Therefore, the methods and media also have similar beneficial technical effects to their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, therefore, The beneficial technical effects of the method and medium will not be repeated here.
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程方法商品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程方法商品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程方法商品或者方法中还存在另外的相同要素。It should also be noted that the terms "comprising", "comprising" or any other variation thereof are intended to encompass a non-exclusive inclusion such that a process, method, commodity or method that includes a list of elements includes not only those elements, but also includes not explicitly Other elements listed, or that are inherent to the commodity or method of the process. Without further limitation, an element qualified by the phrase "comprising a..." does not preclude the presence of additional identical elements in the process method article or method that includes the element.
以上所述仅为本申请的实施例而已,并不用于限制本申请。对于本领域技术人员来说,本申请可以有各种更改和变化。凡在本申请的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本申请的权利要求范围之内。The above descriptions are merely examples of the present application, and are not intended to limit the present application. Various modifications and variations of this application are possible for those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this application shall be included within the scope of the claims of this application.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111232535.8A CN113992626A (en) | 2021-10-22 | 2021-10-22 | Method, device and storage medium for realizing DNS |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202111232535.8A CN113992626A (en) | 2021-10-22 | 2021-10-22 | Method, device and storage medium for realizing DNS |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN113992626A true CN113992626A (en) | 2022-01-28 |
Family
ID=79740359
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202111232535.8A Pending CN113992626A (en) | 2021-10-22 | 2021-10-22 | Method, device and storage medium for realizing DNS |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN113992626A (en) |
Cited By (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115022283A (en) * | 2022-05-24 | 2022-09-06 | 中国科学院计算技术研究所 | A programmable switch supporting domain name resolution and a method for processing network packets |
| CN115378906A (en) * | 2022-08-16 | 2022-11-22 | 北京轻网科技股份有限公司 | VPN framework-based local DNS proxy method, device, equipment and medium |
| CN117692253A (en) * | 2024-02-01 | 2024-03-12 | 鹏城实验室 | Domain name preservation methods, systems and storage media |
Citations (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102025794A (en) * | 2010-01-22 | 2011-04-20 | 中国移动通信集团北京有限公司 | Domain name resolution method, DNS (Domain Name Server) server and system |
| US20150358276A1 (en) * | 2014-05-28 | 2015-12-10 | International Business Machines Corporation | Method, apparatus and system for resolving domain names in network |
| CN105450787A (en) * | 2014-08-20 | 2016-03-30 | 阿里巴巴集团控股有限公司 | Network-address-mapping method, device, and system |
| CN107645573A (en) * | 2017-09-29 | 2018-01-30 | 中国人民解放军国防科技大学 | Method for detecting forwarding configuration of recursive domain name server |
| WO2018090933A1 (en) * | 2016-11-17 | 2018-05-24 | 腾讯科技(深圳)有限公司 | Method, apparatus, and system for resolving service platform address |
| CN109587290A (en) * | 2019-01-04 | 2019-04-05 | 平安科技(深圳)有限公司 | A kind of method and relevant apparatus of domain name mapping |
| WO2019165665A1 (en) * | 2018-02-28 | 2019-09-06 | 网宿科技股份有限公司 | Domain name resolution method, server and system |
| CN110519401A (en) * | 2019-07-05 | 2019-11-29 | 中国平安财产保险股份有限公司 | Improve method, apparatus, equipment and the storage medium of network Access Success Rate |
| CN110933156A (en) * | 2019-11-26 | 2020-03-27 | 杭州迪普科技股份有限公司 | Domain name resolution method and device |
| CN111464521A (en) * | 2020-03-26 | 2020-07-28 | 深圳市酷开网络科技有限公司 | Method, device, computer equipment and storage medium for preventing domain name from being hijacked |
-
2021
- 2021-10-22 CN CN202111232535.8A patent/CN113992626A/en active Pending
Patent Citations (10)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102025794A (en) * | 2010-01-22 | 2011-04-20 | 中国移动通信集团北京有限公司 | Domain name resolution method, DNS (Domain Name Server) server and system |
| US20150358276A1 (en) * | 2014-05-28 | 2015-12-10 | International Business Machines Corporation | Method, apparatus and system for resolving domain names in network |
| CN105450787A (en) * | 2014-08-20 | 2016-03-30 | 阿里巴巴集团控股有限公司 | Network-address-mapping method, device, and system |
| WO2018090933A1 (en) * | 2016-11-17 | 2018-05-24 | 腾讯科技(深圳)有限公司 | Method, apparatus, and system for resolving service platform address |
| CN107645573A (en) * | 2017-09-29 | 2018-01-30 | 中国人民解放军国防科技大学 | Method for detecting forwarding configuration of recursive domain name server |
| WO2019165665A1 (en) * | 2018-02-28 | 2019-09-06 | 网宿科技股份有限公司 | Domain name resolution method, server and system |
| CN109587290A (en) * | 2019-01-04 | 2019-04-05 | 平安科技(深圳)有限公司 | A kind of method and relevant apparatus of domain name mapping |
| CN110519401A (en) * | 2019-07-05 | 2019-11-29 | 中国平安财产保险股份有限公司 | Improve method, apparatus, equipment and the storage medium of network Access Success Rate |
| CN110933156A (en) * | 2019-11-26 | 2020-03-27 | 杭州迪普科技股份有限公司 | Domain name resolution method and device |
| CN111464521A (en) * | 2020-03-26 | 2020-07-28 | 深圳市酷开网络科技有限公司 | Method, device, computer equipment and storage medium for preventing domain name from being hijacked |
Cited By (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN115022283A (en) * | 2022-05-24 | 2022-09-06 | 中国科学院计算技术研究所 | A programmable switch supporting domain name resolution and a method for processing network packets |
| CN115378906A (en) * | 2022-08-16 | 2022-11-22 | 北京轻网科技股份有限公司 | VPN framework-based local DNS proxy method, device, equipment and medium |
| CN115378906B (en) * | 2022-08-16 | 2024-02-13 | 北京轻网科技股份有限公司 | Local DNS proxy method, device, equipment and medium based on VPN framework |
| CN117692253A (en) * | 2024-02-01 | 2024-03-12 | 鹏城实验室 | Domain name preservation methods, systems and storage media |
| CN117692253B (en) * | 2024-02-01 | 2024-05-07 | 鹏城实验室 | Domain name preservation method, system and storage medium |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US20230216884A1 (en) | Method for minimizing the risk and exposure duration of improper or hijacked dns records | |
| US10148612B2 (en) | Method and system for increasing speed of domain name system resolution within a computing device | |
| US6016512A (en) | Enhanced domain name service using a most frequently used domain names table and a validity code table | |
| US8762573B2 (en) | Reverse DNS lookup with modified reverse mappings | |
| JP5893034B2 (en) | Request routing in network environments | |
| JP5974079B2 (en) | Global traffic management using changed hostnames | |
| US11323414B2 (en) | Managing domain name system (DNS) record cache across multiple DNS servers using multicast communication | |
| CN113992626A (en) | Method, device and storage medium for realizing DNS | |
| CN110071986A (en) | A system for domain name resolution | |
| CN108494891A (en) | A kind of domain name analytic method, server and system | |
| JP2004318743A (en) | File transfer device | |
| CN109729187B (en) | Proxy communication method, system, device and storage medium | |
| CN113946587A (en) | Handle identifier analysis caching method, query method and handle identifier analysis system | |
| WO2025139208A1 (en) | Container group scheduling method and system for cluster, and computer device | |
| US20020199020A1 (en) | Method and system for resolving names on a network gateway having multiple distinct network interfaces | |
| CN109495525B (en) | Network component, method of resolving content identification, and computer-readable storage medium | |
| KR101645222B1 (en) | Advanced domain name system and management method | |
| CN105897832A (en) | Service data providing server, method and system | |
| CN117478635A (en) | System and method for preventing error caching of DNS pre-caching | |
| CN117692173A (en) | Request message processing methods, systems and related equipment | |
| CN120729783A (en) | Data packet transmission method, device, electronic device and readable storage medium | |
| CN116888941A (en) | Domain name system for data discovery | |
| CN113949750A (en) | Handle identification parsing cache method, query method and handle identification parsing system | |
| CN103166928A (en) | A method, system and DNS authoritative server for providing information service | |
| Dovey et al. | Networking: Connections, Data, and the Cloud |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20220128 |
|
| RJ01 | Rejection of invention patent application after publication |