> 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/tenants/provide-layer2-to-tenant.md).

# 为租户提供二层访问 - 旧版

{% hint style="success" %}
**较新的配置方法**

在 VergeOS 26.0 及更高版本中，请考虑使用 [租户二层网络](/run-the-platform/tenants/layer-2-networks.md) 以更简单、更精简的方式为租户提供二层访问。此方法会在租户环境中自动创建所需的网络。
{% endhint %}

{% hint style="info" %}
**术语更新**

在较早版本的 VergeOS 文档中，Virtual Switch Ports 之前称为“Virtual Wires”。功能保持不变——仅为提高清晰度更新了术语。
{% endhint %}

### 高级步骤

1. **准备物理网络：** 验证 VLAN 已在相应的物理交换机端口上配置，以便它们可在 VergeOS 环境中访问。

{% hint style="warning" %}
VLAN 1 和 100-102 不能用于虚拟交换端口。这些 VLAN 预留给内部流量。不过，这些 ID 可以重新映射为其他 VLAN ID 供租户使用。
{% endhint %}

2. **创建虚拟交换端口** 确定租户是否需要访问单个 VLAN 还是多个 VLAN。 **这将决定虚拟交换端口配置**:
   * 若要传递单个 VLAN，请使用 [创建 1:1 虚拟交换端口](#creating-a-11-virtual-wire) 每个 VLAN 的说明。
   * 如果租户需要访问超过 1 或 2 个 VLAN，通常最好使用 [创建 Trunk 模式虚拟交换端口](#creating-a-trunk-mode-virtual-wire) 说明。

{% hint style="info" %}
**虚拟交换端口主机放置**

使用虚拟交换端口时，参与该虚拟交换端口的两个网络 **必须位于同一主机上**。未满足此要求可能会导致网络连接问题。
{% endhint %}

3. [在租户内添加 VLAN](#add-vlans-inside-the-tenant)

### 创建 1:1 虚拟交换端口

1. 确保 VLAN 已在 VergeOS UI 中配置。否则，请按照步骤创建 VLAN [这里](/run-the-platform/networking/create-vlan.md).
2. 选择 **网络** 然后 **仪表板** 从顶部菜单打开网络仪表板。
3. 选择 **虚拟交换端口** 在左侧菜单中查看环境中的所有虚拟交换端口。
4. 选择 **新建** 以创建 **虚拟交换端口的前半部分：**
   * **名称**：描述性名称，例如来自主机的 VLAN 等。
   * **网络**：包含相应 VLAN、用于传递给租户的外部网络
   * **目标连线**：字段应显示 ***--空列表--*** 或选择 ***--无--***
   * **PVID**: 1.\
     **示例配置：**
5. **提交** 您的更改并返回虚拟交换端口列表视图。
6. 选择 **新建** 以创建 **虚拟交换端口的后半部分：**
   * **名称**：用于标识该连线的名称，例如 VLAN ID、租户、用途等
   * **网络**：租户网络，通常命名为 `tenant_'$TENANTNAME'`.
   * **目标连线**：上面创建的虚拟交换端口的另一半。
   * **PVID**：所连接网络的 VLAN ID。\
     **示例配置：**
7. **提交** 您的更改。
8. 导航到 **网络仪表板**，选择“网络”，然后 **应用规则** 适用于由虚拟交换端口连接的两个网络。

### 创建 Trunk 模式虚拟交换端口

{% hint style="info" %}
**需要桥接模式**

若要使用 trunk 模式虚拟交换端口，相应的物理网络（绑定到节点 NIC） **必须** 设置为桥接模式。
{% endhint %}

#### 将物理网络设置为桥接模式

1. 从顶部菜单中选择 **网络** > **列表**.
2. 双击 **物理网络** （NIC），即 VLAN 在物理交换机上汇聚到的接口。

{% hint style="success" %}
物理网络通常在名称后附加“Switch”，并表示节点上的一个物理 NIC。您可以按“Type”筛选网络列表，仅显示物理网络。
{% endhint %}

3. 选择 **编辑** 进入网络配置页面。
4. 在配置页面中，启用 **物理桥接** 以激活桥接模式。最好将 **断电后** 设置为 ***开机*** 以便系统断电后网络可自动启动。
5. **提交** 您的更改。
6. **重新启动** 必要的节点，使桥接模式生效。

{% hint style="warning" %}
**遵循正确的** [**维护模式**](/run-the-platform/operations/maintenance-mode.md) **在重启节点时应遵循相关流程，以避免影响工作负载。**
{% endhint %}

#### 配置 trunk 模式虚拟交换端口

1. **确保&#x20;*****物理网络*****&#x20;已设置为桥接模式并已通电启动。**
2. 导航到 **网络** > **虚拟交换端口**.
3. 选择 **新建** 以创建 **虚拟交换端口的前半部分。**
   * **名称**：标识该连线，例如“来自主机的 trunk”
   * **网络**：带有相应 VLAN、用于传递给租户的物理网络。
   * **目标连线**：应显示 ***--空列表--*** 或选择 ***--无--***
   * **PVID**: 0
   * **允许的 VLAN 列表**：用逗号分隔，并在需要时使用范围。\
     **示例配置：**
4. **提交** 您的配置。
5. 选择 **新建** 以创建 **虚拟交换端口的后半部分**.
   * **网络** 在下拉菜单中，选择将接收该 VLAN 的租户网络，通常命名为 `tenant_'$TENANTNAME'`.
   * **PVID**: 0
   * **允许的 VLAN 列表**：用逗号分隔，并在需要时使用范围。\
     **示例配置：**
6. **提交** 您的更改。
7. 导航到 **网络仪表板**，选择“网络”，然后 **应用规则** 适用于由虚拟交换端口连接的两个网络。

### 在租户内添加 VLAN

1. 导航到 **租户 UI** 并登录。
2. 选择 **网络** > **+ 新建外部** 从顶部菜单中。
3. 配置设置：
   * **名称**：用于标识网络的标签（名称、VLAN ID、用途等）
   * **二层类型：** *VLAN*
   * **二层 ID：** VLAN ID
   * **接口网络：** *物理*
   * **IP 地址类型：** *无*\
     **示例配置：**

{% hint style="info" %}
**除非需要特定配置，否则请将其他字段保留默认设置。有关其他外部网络选项的信息，请参见：** [**如何创建外部网络**](/knowledge-base/zh/networking/create-external-network.md)
{% endhint %}

4. **提交** 您的配置。
5. 将工作负载连接到该网络，以获得对 VergeOS 外部网络的二层访问。

### 故障排除步骤

#### 流量未到达虚拟机

* 确认与虚拟交换端口相关的防火墙规则已应用。
* 验证目标租户网络和 VLAN 网络处于“运行中”状态，并位于同一物理节点上。
* 确保 VLAN 已在正确的物理节点端口上进行 trunk。


---

# 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/tenants/provide-layer2-to-tenant.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.
