NS记录

DNS记录类型
名称服务器记录。
← 返回词汇表

什么是 NS 记录?

NS 记录(名称服务器记录)是 DNS 记录类型之一,用于指定对特定域名具有权威性的 DNS 服务器。NS 记录委派 DNS 解析权,告诉全球 DNS 系统应在哪里查找域名或子域名的正式 DNS 信息。每个已注册域名都必须至少有两条 NS 记录指向其权威名称服务器,以提供冗余和可靠性。

NS 记录如何工作

DNS 委派链

Root servers (.): "Who handles .com?"

.com servers: "example.com is delegated to ns1.example.com"

ns1.example.com: "Here are the actual DNS records"

记录格式

example.com.    IN    NS    ns1.example.com.

example.com. IN NS ns2.example.com.

│ │ │ │

│ │ │ └── Target nameserver

│ │ └── Record type

│ └── Class (Internet)

└── Domain name

NS 记录类型

域名 NS 记录

为整个域名委派权威:

example.com.    NS    ns1.dnsprovider.com.

example.com. NS ns2.dnsprovider.com.

子域名委派

将子域名委派给其他名称服务器:

subdomain.example.com.    NS    ns1.subdomain-provider.com.

subdomain.example.com. NS ns2.subdomain-provider.com.

胶水记录

当名称服务器位于被委派的域名内时,胶水记录会提供 IP 地址,以避免循环依赖:

问题

example.com NS ns1.example.com

# How to find ns1.example.com without resolving example.com first?

解决方案(胶水记录)

example.com.        NS    ns1.example.com.

ns1.example.com. A 192.0.2.1

胶水记录存储在父区域(注册局层级),用于启动解析。

NS 记录配置

在注册局层级

注册域名时,需要指定名称服务器:

在 DNS 提供商层级

在区域文件中:

@    IN    NS    ns1.example.com.

@ IN NS ns2.example.com.

最佳实践

冗余要求

最少建议最多
2 条 NS 记录3-4 条 NS 记录13 条 NS 记录

地理分布

TTL 考量

example.com.  86400  IN  NS  ns1.example.com.

↑ 24 hours is common for NS records

常见 NS 记录场景

使用注册商的名称服务器

example.com.    NS    ns1.registrar.com.

example.com. NS ns2.registrar.com.

使用第三方 DNS 提供商

example.com.    NS    ns1.cloudflare.com.

example.com. NS ns2.cloudflare.com.

自托管名称服务器

example.com.    NS    ns1.example.com.

example.com. NS ns2.example.com.

# Requires glue records

检查 NS 记录

使用 dig

dig example.com NS

# Response shows authoritative nameservers

;; ANSWER SECTION:

example.com. 86400 IN NS ns1.example.com.

example.com. 86400 IN NS ns2.example.com.

使用 nslookup

nslookup -type=NS example.com

排查 NS 问题

常见问题及解决方案:

NS 记录构成 DNS 委派的基础,决定任何域名或子域名的查询应由哪些服务器负责回答。

将知识付诸实践

使用 DomScan 的 API 检查域名可用性、健康状态等。