> For the complete documentation index, see [llms.txt](https://docs.verge.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verge.io/knowledge-base/zh/networking/ipsec-example-tenant-nat-ui-ip.md).

# IPsec 配置示例 - 租户/NAT

以下示例在 VergeOS 租户中配置一个 IPsec 对端。在此示例中，用于访问租户 UI 的专用 IP 地址也用于 IPsec 隧道，并通过 NAT 规则来适当地引导隧道流量。

{% hint style="info" %}
**此示例适用于使用专用 IP 地址的租户；使用共享地址（通过代理/PAT 规则）的租户将需要不同的配置。**
{% endhint %}

{% hint style="info" %}
**IPsec 是一个复杂的框架，支持大量配置组合，并且有多种方式实现同一目标，因此不可能提供适用于所有情况的通用说明。以下示例配置仅供参考，应根据具体环境和需求进行调整。**
{% endhint %}

{% hint style="success" %}
**请参阅** [**IPsec 产品指南页面**](/run-the-platform/vpn/ipsec.md) **，了解创建 IPsec 隧道的通用分步说明。**
{% endhint %}

## 主机配置

将 UI 地址分配给租户后，会自动在主机系统（外部网络和租户网络）上创建规则，以适当地转发流量。主机上不应再需要其他配置。

{% hint style="info" %}
**下面概述的所有配置都在租户系统内完成。**
{% endhint %}

## VPN 网络配置

![VPN 网络配置](/files/9c5391fd9ace4fbe0fe8710126a3fa754d1820a8)

## 阶段 1

![阶段 1 配置](/files/a073b1cca82149d2a1c672c1bc5e619b9565e40f)

## 阶段 2

![阶段 2 配置](/files/fea6c0657b36c0d282c48c67403f572ed3c895a1)

## 默认 VPN 网络规则

**默认防火墙规则** - 以下必要的防火墙规则会 **自动创建** ，当创建 VPN 网络时：

* **允许 IKE**：接受到端口 500 的入站 UDP 流量到 **我的路由器 IP**
* **允许 IPsec NAT 穿越**：接受到端口 4500 的入站 UDP 流量到 **我的路由器 IP**
* **允许 ESP**：接受入站 ESP 协议流量到 **我的路由器 IP**
* **允许 AH**：接受入站 AH 协议流量到 **我的路由器 IP**

![查看规则](/files/3dbcffd115878cbb47118e6ee9996b6b2e9681d7)

{% hint style="success" %}
**在适当情况下，这些规则可以修改为仅限制特定源地址。**
{% endhint %}

## 其他 VPN 网络规则

需要在我们新的 VPN 网络上创建其他规则：

**VPN NAT 规则：** ![VPN NAT Rule](/files/76e79e03299ada08bd0d4ce7d92ef62b0998a29b)

{% hint style="success" %}
**传入的 NAT 规则必须移到顶部，置于……之前。&#x20;*****接受*****&#x20;规则之前。有关更改规则顺序的说明，请参见产品指南：** [**网络规则 - 更改规则顺序**](/run-the-platform/networking/network-rules.md#change-the-order-of-rules)
{% endhint %}

**默认路由规则：** ![VPN Default Route Rule](/files/85cfe43890a236a1de7318079a2e32b512bb43bf)

**VPN SNAT 规则：** ![VPN Nat Rule](/files/6f9d9f352bfc02d4a0c4fc89cec5463b867227e1)

## 外部网络规则

需要在租户的外部网络上配置转换规则，以将 IPsec 流量发送到 VPN 网络：

**外部 UDP NAT 规则：** ![VPN Nat Rule](/files/17958709333cbe63733d72fa9f60e6b9462fa070)

**外部 ESP NAT 规则：** ![VPN Nat Rule](/files/8fdd28f1c0ae705c58aea806a12ddd603f19e425)

**外部 AH NAT 规则：** ![VPN Nat Rule](/files/f34ea1af96b3b32706b72cbd986d246f2f3b9d8c)

## 将内部网络连接到 VPN

可以在 VPN 网络和其他内部网络之间配置路由，以便为这些网络提供隧道访问；参见 [如何配置网络之间的路由](/knowledge-base/zh/networking/routing-between-internal-vergeio-networks.md).

{% hint style="success" %}
**新规则必须应用到每个网络上才能生效。**
{% endhint %}


---

# 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.verge.io/knowledge-base/zh/networking/ipsec-example-tenant-nat-ui-ip.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.
