> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/welcome/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/welcome/cn/elastic-compute/get-started/manage-networking/create-a-public-nat-gateway/configure-dnat-rules.md).

# 配置 DNAT 规则

在公网 NAT 网关上配置 DNAT（目标网络地址转换）规则，通过端口或 IP 映射将公网 IP 地址与实例关联，使实例能够通过互联网提供服务。

## 操作步骤

1. 在详情页面上，转到 **NAT 规则** > **创建 DNAT 条目**

   <div align="left"><figure><img src="/files/trWI58YqfDEWkS90GDs8" alt="" width="563"><figcaption></figcaption></figure></div>
2. 设置公网入站 IP\
   选择接收入站流量的弹性 IPv4 地址。
   * 只有已绑定到当前 NAT 网关的弹性 IP 会列出。
   * 如果没有合适的弹性 IP，点击 **新建弹性 IPv4** 创建并绑定一个。
3. 选择内网 IP

   选择流量将被转发到的私有端点。有两种选择：

   * **按 vNIC/按实例**\
     选择与 vNIC 或实例关联的内网 IP。
   * **自定义内网 IP**\
     手动输入一个内网 IP 地址。\
     如果内网 IP 未关联到实例，路由将不会生效。
4. 配置协议和端口\
   定义 DNAT 映射使用的协议和端口。
   * **任意端口**\
     将来自公网 IP 的所有流量转发到内网 IP，不指定端口（IP 映射）。
   * **自定义端口**\
     指定 **公网端口**、**内网端口** 和 **协议**（TCP 和 UDP），以实现细粒度控制（端口映射）。
5. 点击 **确认** 保存并应用 DNAT 条目。

{% hint style="info" %} <mark style="color:blue;">**注意**</mark>

<mark style="color:blue;">当 SNAT 也已配置时，DNAT 映射的弹性 IP 在出站访问中具有优先权。请确保端口映射和 IP 选择不冲突。</mark>
{% endhint %}

## 结果

在 DNAT 规则列表页面，您可以编辑和删除现有的 DNAT 条目。

{% hint style="info" %} <mark style="color:blue;">**注意**</mark>

* <mark style="color:blue;">编辑 NAT 规则可能会导致服务中断。请谨慎操作。</mark>
* <mark style="color:blue;">删除资源可能会影响正在进行的服务。相关资源将被解绑。请谨慎操作。</mark>
  {% endhint %}

## 示例

**将 TCP 端口 8080 映射到私有实例的端口 80**

为了允许外部 HTTP 访问托管在私有实例上的 Web 服务，您可以配置一个自定义协议和端口映射的 DNAT 规则。

**配置示例：**

* **弹性 IP（公网 IP）**: `203.0.113.5`
* **协议**: `TCP`
* **公网端口**: `8080`
* **内网 IP**: `192.168.1.100`
* **内网端口**: `80`

**效果：**

发送到 `203.0.113.5:8080` 的任何 TCP 流量都将由 NAT 网关转发到您全球 VPC 中的 `192.168.1.100:80`。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.console.zenlayer.com/welcome/cn/elastic-compute/get-started/manage-networking/create-a-public-nat-gateway/configure-dnat-rules.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
