什么是胶水记录?
胶水记录(Glue Record)是存储在父级 DNS 区域中的 A 或 AAAA 记录。当名称服务器的主机名位于其所服务的域名内部时,胶水记录提供该名称服务器的 IP 地址,从而避免 DNS 解析中的循环依赖。循环依赖问题
Without Glue Records (Circular Dependency):
Query: "What is the IP of www.example.com?"
↓
Resolver asks: "Who are the nameservers for example.com?"
↓
Answer: ns1.example.com
↓
Resolver asks: "What is the IP of ns1.example.com?"
↓
Needs to query example.com nameservers...
↓
But we don't know their IP! (Loop)
胶水记录如何解决问题
With Glue Records at .com TLD:
.com Zone File:
example.com. NS ns1.example.com.
example.com. NS ns2.example.com.
ns1.example.com. A 192.0.2.1 ← Glue Record
ns2.example.com. A 192.0.2.2 ← Glue Record
Resolution Flow:
Query for www.example.com
↓
.com servers return NS records + Glue IPs
↓
Resolver can now contact 192.0.2.1 directly
↓
Resolution completes successfully
何时需要胶水记录
| 名称服务器位置 | 是否需要胶水 | 示例 |
|---|---|---|
| 位于同一域名内 | 是 | example.com 的 ns1.example.com |
| 位于其他域名内 | 否 | example.com 的 ns1.hostingco.com |
| 目标域名的子域名 | 是 | example.com 的 ns1.dns.example.com |
胶水记录类型
| 记录类型 | 用途 | 示例 |
|---|---|---|
| A | 名称服务器的 IPv4 地址 | ns1.example.com A 192.0.2.1 |
| AAAA | 名称服务器的 IPv6 地址 | ns1.example.com AAAA 2001:db8::1 |
常见配置场景
Scenario 1: Self-hosted nameservers
Domain: example.com
Nameservers: ns1.example.com, ns2.example.com
→ Glue records REQUIRED at registrar
Scenario 2: Third-party nameservers
Domain: example.com
Nameservers: dns1.provider.com, dns2.provider.com
→ No glue records needed
Scenario 3: Vanity nameservers pointing elsewhere
Domain: example.com
Nameservers: ns1.example.com → CNAME dns1.provider.com
→ INVALID - NS records cannot point to CNAMEs
→ Must use glue records with actual IPs
管理胶水记录
胶水记录在域名注册商处配置,而不是在 DNS 区域文件中配置:
1. 登录注册商控制面板
2. 打开名称服务器或主机记录部分
3. 创建包含名称服务器主机名和 IP 的主机记录
4. 将这些名称服务器分配给域名
最佳实践
1. 同时提供 IPv4 和 IPv6:添加 A 和 AAAA 胶水记录
2. 使用多个 IP:为 ns1 和 ns2 使用不同 IP,提供冗余
3. 保持记录更新:名称服务器 IP 变化时同步修改胶水记录
4. 验证传播:使用 dig +trace 检查胶水记录
故障排查
# Check glue records for a domain
dig +trace example.com NS
# Verify glue is present in TLD response
dig @a.gtld-servers.net example.com NS +norec
胶水记录是 DNS 基础设施的重要组成部分,让域名可以使用自托管名称服务器,同时保持 DNS 层级可解析。