# ZDNS 服务

## 简介

Zenlayer DNS（ZDNS）是一款由 Zenlayer 弹性算力提供的**全球统一配置、区域就近提供**的高可用 DNS 服务。

ZDNS 集群采用无状态架构，每台服务器均可独立对外提供解析能力。集群内所有服务器通过 BGP 宣告相同的 VIP，当某个节点出现异常时，其 BGP 会自动撤销，流量将切换至其他健康节点，从而确保服务的高可用性。

ZDNS 系统默认使用 TCP/UDP 53 端口，解析器地址如下：

* **IPv4**: `169.254.169.253`
* **IPv6**: `fd00:a9fe:a9fd::1`

ZDNS 支持 **内网域名解析** 与 **外网递归解析**。通过内网解析，您可以实现服务发现、负载均衡和服务高可用等能力。您还可以利用内网域名记录，对 VPC 内的多种云资源（如云主机、负载均衡等）进行统一管理，从而进一步提升资源的管理效率与可用性。

<div align="left"><figure><img src="/files/RZglI4x16jnkIRl7tEDZ" alt="" width="563"><figcaption></figcaption></figure></div>

## 功能特性

* **高可用**：单节点故障不会影响整体解析，流量将自动切换到健康节点。
* **无状态架构**：节点可快速上线/下线，无需进行全局状态同步。
* **横向扩展**：新增节点可立即提升集群的整体处理能力。
* **VPC 隔离**：支持不同 VPC 的内网权威域名解析。
* **公网递归解析**：可对未命中的域名发起公网递归查询。
* **内网权威子域递归**：当匹配到内网父域但未命中子域时，可自动回退到公网进行递归解析。

## ZDNS 解析流程

1. **客户端配置**

   客户端（虚拟机）需要将 DNS 服务器地址配置为：

   * **IPv4：**`169.254.169.253`
   * **IPv6**：`fd00:a9fe:a9fd::1`
2. **请求接入**\
   当客户端向上述 DNS 地址发起请求时，请求将自动路由至对应区域的 ZDNS 集群。
3. **合法性检查**\
   ZDNS 集群会首先验证请求是否为合法 DNS 报文，仅合法请求才会继续处理。
4. **域名解析**
   * **未命中内网权威域名**：\
     请求将转发至公网进行递归解析，并返回最终结果。
   * **命中 VPC 内网权威域名**：
     * **命中子域名**：直接解析并返回结果。
     * **未命中子域名**：
       * **已开启递归**：转发至公网递归解析，并返回最终结果。
       * **未开启递归**：返回空响应。
5. **返回客户端**\
   解析完成后，ZDNS 将结果返回给客户端，提供快速、可靠的 DNS 响应。

## **虚拟机 DNS 配置**

目前仅支持手动修改虚拟机的 DNS 服务器，未来将支持通过 DHCP 选项自动设置默认 DNS。

* **IPv4 虚拟机默认 DNS：**`169.254.169.253`
* **纯 IPv6 虚拟机默认 DNS：**`fd00:a9fe:a9fd::1`

### **CentOS（含 CentOS 7/9）**

#### **1.** 临时配置

修改 `/etc/resolv.conf`：

```bash
sudo vim /etc/resolv.conf
```

添加内容：

```
nameserver 169.254.169.253
```

保存退出即可生效。

#### **2.** 持久化配置

编辑当前网卡配置文件 `/etc/sysconfig/network-scripts/ifcfg-eth0`：

```bash
sudo vim /etc/sysconfig/network-scripts/ifcfg-eth0
```

追加以下内容：

```
DNS1=169.254.169.253
PEERDNS=no
```

默认文件示例：

```
# Created by cloud-init on instance boot automatically, do not edit.
BOOTPROTO=dhcp
DEVICE=eth0
DHCPV6C=yes
IPV6INIT=yes
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no
DNS1=169.254.169.253
PEERDNS=no
```

#### **3. 检查**

运行：

```bash
sudo cat /etc/resolv.conf
```

输出示例：

```
nameserver 169.254.169.253
```

***

### **Ubuntu（含 20.04/22.04/24.04）**

#### **1.** 配置（推荐 Netplan）

编辑网卡配置文件 `/etc/sysconfig/network-scripts/ifcfg-eth0`:

```bash
sudo vim /etc/netplan/50-cloud-init.yaml
```

追加以下内容：

```yaml
dhcp4-overrides:
    use-dns: false
dhcp6-overrides:
    use-dns: false
nameservers:
    addresses:
      - 169.254.169.253
```

完整示例（请替换为实际 MAC 地址）：

```yaml
# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            match:
                macaddress: 52:54:00:8d:a7:d3
            set-name: eth0
            dhcp4-overrides:
                use-dns: false
            dhcp6-overrides:
                use-dns: false
            nameservers:
                addresses:
                  - 169.254.169.253
```

#### **2.** 刷新网络

```bash
sudo netplan apply
```

#### **3. 检查**

运行：

```bash
sudo resolvectl
```

输出示例：

```
DNS Servers: 169.254.169.253
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.console.zenlayer.com/welcome/cn/elastic-compute/zdns-service.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
