头图

DNS series (2): DNS records and how they work, do you understand?

In the previous article "DNS Series (1): Why does the updated DNS record not take effect? " , we mainly explained DNS and DNS propagation, we know that network communication is mainly carried out through IP addresses, and the Domain Name System (DNS) is to ensure that users can access the corresponding website server after entering the domain name in the browser. So how does this process work?

DNS records

DNS records are instructions located in authoritative DNS servers that provide details about a domain and hostname, including which IP addresses are associated with the domain, and how requests for the domain are handled.

When we enter the website address in the browser, the browser will first look up the IP address belonging to the domain name in the internal cache of the computer.

A DNS record consists of a series of text files written in DNS syntax. There is a separate line for each DNS record. Records generally follow the following format:

 <name> <ttl> <class> <type> <rdlength> <radata>
  • <name>: refers to the domain, which is the name that the user enters in the browser
  • <ttl>: TTL stands for "time to live" and represents the time (in seconds) a record can be temporarily stored in the cache
  • <class>: In theory, there are different classes of DNS records. In practice, however, the record is often the Internet (ie IN),
  • <type>: different record types
  • <rdlength>: Specifies the size of the subsequent data field (optional value)
  • <rdata>: The parsed domain name information (such as IP address)

We can use Dig command to query DNS record information, for example: www.example.com

 www.example.com.  69288  IN  A  93.184.216.34

This means that the record can be stored in the cache for 69288 seconds, it refers to a DNS record (IN) on the Internet and points to a class A record, and the domain name is resolved to an IP address (93.184.216.34).

DNS record type

We mentioned above that there are different types of DNS records. This actually refers to the type of information in the records. The more common ones are as follows:

A record

Most DNS resolutions on the Internet are done through Class A records and point to an IPv4 address. Through this record, after the user enters the domain name in the browser, the client sends an HTTP request to the corresponding IP address. Since the size of an IPv4 address is always 4 bytes, the value of rdlength is always 4.

AAAA records

AAAA records, also known as "quad A", function the same as A records. However, it points to an IPv6 address. Because the length of IPv6 is 128 bits (16 bytes), rdlength is also predefined as 16 here.

SOA records

SOA records contain zone information for zone files or DNS servers. Because DNS zone transfer is the process of sending DNS record data from a primary name server to a secondary name server, and SOA records are transferred first, an SOA record is required for each DNS zone.

CNAME record

A CNAME record (canonical name record) points the record value to an alias domain, not an IP address. For this type, the rdata field is populated with a domain name that can continue to point to the next domain name or IP address.

MX records

MX records refer to mail exchanges or SMTP email servers. Multiple MX records can exist, and the order of use is determined by specifying a priority.

PTR records

PTR records (pointers) are DNS records that allow reverse lookups. Contrary to the "A" record, it can look up the corresponding domain name by IP address.

NS records

NS (Domain Name Server) records define the jurisdiction of a particular area. A domain typically has multiple NS records that indicate the domain's primary and secondary nameservers. A properly configured NS record tells the Internet where to find the domain's IP address to load a website or application.

TXT record

TXT records contain text for user or machine readable information. A domain can have many TXT records.

SRV records

Through SRV records, the server can provide host and port information for some specific services, such as instant messaging. Some Internet protocols require the use of SRV records to function.

In addition to these common DNS records, there are many less commonly used record types, such as: APL, CAA, DNAME, and so on. Knowing the DNS records, the next step is to take a detailed look at how DNS requests these records.

DNS request

Whenever we enter a URL in the search bar of the browser, a request is made to the local name server (Local DNS). Local DNS is a component that checks if a record is in the local cache, and its queries are recursive/iterative queries.

Client and Local DNS are recursive query, which is the most common query method. Specifically, if Local DNS cannot respond to the request, it will continue to send query requests to other root domain name servers on behalf of the client, that is, continue the query for the client, instead of letting the client perform the next query by itself.

And between Local DNS and other name servers is an iterative query. Specifically, if the DNS server requested by Local DNS cannot answer the query, then it will return the address of the next DNS server as a response. Then Local DNS sends a new request to the next DNS server, and continues to search until the record is found.

Therefore, the overall query process of Local DNS is to first record the previously obtained IP address in the cache, and then deliver the result to the client according to the request. If the required record is not in the Local DNS cache, the request will be forwarded to the corresponding ISP's DNS server. If the current DNS server cannot answer this query, it will forward the request to a different DNS server.

Note that recursive queries are usually faster than iterative queries. Because the recursive DNS server caches the result of every query it performs and saves the result for a TTL time. When a recursive resolver receives a query for an IP address already in its cache, it can quickly serve the result to the client without having to communicate with other DNS servers. However, allowing recursive queries on an open DNS server creates security holes, and this configuration is vulnerable to DNS amplification attacks and DNS cache poisoning.

Knowing the DNS records, next time you encounter the error message that the website cannot be accessed, you can prioritize whether there is a DNS problem. If you're a website administrator, you can check to see if your DNS records are misconfigured, or if your DNS server isn't responding. If you are a website visitor, you can try to switch the network or change the local DNS to solve it.

Recommended reading

The road to improvement of cloud Redis

About the routing tree of GIN

What is walking index?


云叔
-- 隐于云端,静闻天籁 --

又拍云是专注CDN、云存储、小程序开发方案、 短视频开发方案、DDoS高防等产品的国内知名企业级云服务商。

5.7k 声望
4.6k 粉丝
0 条评论
推荐阅读
一文读懂 Kubernetes 存储设计
在 Docker 的设计中,容器内的文件是临时存放的,并且随着容器的删除,容器内部的数据也会一同被清空。不过,我们可以通过在 docker run 启动容器时,使用 --volume/-v 参数来指定挂载卷,这样就能够将容器内部的...

云叔_又拍云阅读 340

封面图
正则表达式实例
收集在业务中经常使用的正则表达式实例,方便以后进行查找,减少工作量。常用正则表达式实例1. 校验基本日期格式 {代码...} {代码...} 2. 校验密码强度密码的强度必须是包含大小写字母和数字的组合,不能使用特殊...

寒青55阅读 7.8k评论 11

JavaScript有用的代码片段和trick
平时工作过程中可以用到的实用代码集棉。判断对象否为空 {代码...} 浮点数取整 {代码...} 注意:前三种方法只适用于32个位整数,对于负数的处理上和Math.floor是不同的。 {代码...} 生成6位数字验证码 {代码...} ...

jenemy46阅读 6k评论 12

从零搭建 Node.js 企业级 Web 服务器(十五):总结与展望
总结截止到本章 “从零搭建 Node.js 企业级 Web 服务器” 主题共计 16 章内容就更新完毕了,回顾第零章曾写道:搭建一个 Node.js 企业级 Web 服务器并非难事,只是必须做好几个关键事项这几件必须做好的关键事项就...

乌柏木66阅读 6.2k评论 16

再也不学AJAX了!(二)使用AJAX ① XMLHttpRequest
「再也不学 AJAX 了」是一个以 AJAX 为主题的系列文章,希望读者通过阅读本系列文章,能够对 AJAX 技术有更加深入的认识和理解,从此能够再也不用专门学习 AJAX。本篇文章为该系列的第二篇,最近更新于 2023 年 1...

libinfs39阅读 6.3k评论 12

封面图
从零搭建 Node.js 企业级 Web 服务器(一):接口与分层
分层规范从本章起,正式进入企业级 Web 服务器核心内容。通常,一块完整的业务逻辑是由视图层、控制层、服务层、模型层共同定义与实现的,如下图:从上至下,抽象层次逐渐加深。从下至上,业务细节逐渐清晰。视图...

乌柏木44阅读 7.4k评论 6

CSS 绘制一只思否猫
欢迎关注我的公众号:前端侦探练习 CSS 有一个比较有趣的方式,就是发挥想象,绘制各式各样的图案,比如来绘制一只思否猫?思否猫,SegmentFault 思否的吉祥物,是一只独一无二、特立独行、热爱自由的(&gt;^ω^&lt...

XboxYan43阅读 2.9k评论 14

封面图

又拍云是专注CDN、云存储、小程序开发方案、 短视频开发方案、DDoS高防等产品的国内知名企业级云服务商。

5.7k 声望
4.6k 粉丝
宣传栏