> 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/cloud-networking/get-started/validate-connection-in-public-cloud/amazon-web-service-aws-configuration.md).

# AWS Direct Connect 配置

AWS 侧的专线配置：创建网关、接收托管连接、配置虚拟接口并建立 BGP 会话。

## 背景信息

AWS Direct Connect（简称 DX）是 AWS 提供的专线接入服务，用于在您的本地环境与 AWS 云网络之间建立专属的高速连接。通过 Zenlayer 的任一 DX 接入点，您可以在自有数据中心或其他云环境与 AWS 之间构建一条私有链路。

与基于公网的 VPN 不同，DX 全程依托供应商与 AWS 之间的专属物理线路，与互联网彻底隔离，带宽稳定、安全性与可靠性更高。

根据您在 AWS 控制台上的配置，Direct Connect 支持三种虚拟接口（VIF）：

* **Public VIF**（公共虚拟接口）——访问 AWS 的公共服务端点，例如 Amazon S3、DynamoDB 等无需部署在 VPC 内的服务。
* **Private VIF**（私有虚拟接口）——直连您的 VPC，使用您规划的私有 IP 访问 VPC 内的资源（如 EC2 实例、Elastic Load Balancer）。
* **Transit VIF**（中转虚拟接口）——将 Direct Connect 网关关联至 AWS Transit Gateway，实现本地数据中心与多个 VPC、以及 VPC 之间的互联，共用同一条连接。

您的本地工作负载通过 Zenlayer 提供的虚拟电路，在 Direct Connect 接入点接入 AWS：

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-4134715dda00ae812d2d8309a7b8d6d150835bf8%2Faws-dx-overview.png?alt=media" alt=""><figcaption><p>AWS Direct Connect 连接示意</p></figcaption></figure>

## 名词解释

| 名称                               | 说明                                                  |
| -------------------------------- | --------------------------------------------------- |
| **VPC**（Virtual Private Cloud）   | 虚拟私有云，AWS 账户下基于区域的虚拟网络环境                            |
| **VGW**（Virtual Gateway）         | VPC 的虚拟私有网关                                         |
| **DXGW**（Direct Connect Gateway） | 全球可用的专线网关，可关联多个区域的 VGW，是上云专线的核心组件，也是部署 VIF 的载体      |
| **TGW**（Transit Gateway）         | 中转网关，区域内的网络核心，可连接同区域的大量 VPC                         |
| **VIF**（Virtual Interface）       | 虚拟接口，AWS 网络侧的逻辑端口，分 Public / Private / Transit 三种类型 |

术语定义参考 [**AWS Direct Connect 常见问题**](https://aws.amazon.com/cn/directconnect/faqs/)。

## 操作步骤

AWS 侧的整体配置流程如下：

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-213d9fe7ad108a8a7465cc3a954d8adefb9ecc6a%2FAWS%E4%B8%93%E7%BA%BF%E9%85%8D%E7%BD%AE%E6%B5%81%E7%A8%8B.svg?alt=media" alt=""><figcaption><p>AWS 侧配置流程</p></figcaption></figure>

下图以通过 Zenlayer 专线网络对接 AWS Direct Connect 为例，配置 Private VIF 后即可访问 VPC 中的 EC2 等私有资源：

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-646ca317071a5d0b5715dfed0a0747ed4f7c4b41%2Faws-dx-architecture.png?alt=media" alt=""><figcaption><p>多区域 VPC 经 DXGW / TGW 接入 AWS</p></figcaption></figure>

本地与 AWS 之间的 BGP 对接有两种方式：

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-2704006c91ea4ef8b343dc75f3e98719a1735f2a%2Faws-dx-bgp-peering-modes.png?alt=media" alt=""><figcaption><p>两种 BGP Peering 对接方式</p></figcaption></figure>

{% stepper %}
{% step %}
**创建虚拟私有网关（VGW）**

进入 Direct Connect 服务页面，选择 **Virtual private gateways**，点击 **Create virtual private gateway**。VGW 的 ASN 可由您自行指定，也可使用 AWS 默认的 `64512`。

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-50602738a880afe14353a4efccded0ec9c3fba4b%2Faws-dx-vgw-1.png?alt=media" alt=""><figcaption><p>创建虚拟私有网关 VGW</p></figcaption></figure>

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-9ba740b4dc90fa5ed6321d8ae1e708e26647db2e%2Faws-dx-vgw-2.png?alt=media" alt=""><figcaption><p>指定 VGW 名称与 ASN</p></figcaption></figure>
{% endstep %}

{% step %}
**创建 Direct Connect 网关（DXGW）**

进入 Direct Connect 服务页面，选择 **Direct Connect gateways**，点击 **Create Direct Connect gateway**。

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-cbd4abb03a0a25cf041e3fcb1e84a151c9aeea5a%2Faws-dx-dxgw-1.png?alt=media" alt=""><figcaption><p>创建 Direct Connect 网关 DXGW</p></figcaption></figure>

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-7318983e9d27ecbf9bcc2a2f6fe5f096878f3748%2Faws-dx-dxgw-2.png?alt=media" alt=""><figcaption><p>填写 DXGW 名称与 ASN</p></figcaption></figure>
{% endstep %}

{% step %}
**关联 VPC 与 VGW**

将已创建的虚拟私有网关与目标 VPC 关联，使 VPC 流量具备进入专线的出口。

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-8c1975d47c5531028840fd47ddd11d7ea533ae78%2Faws-dx-vpc-vgw-1.png?alt=media" alt=""><figcaption><p>关联 VPC 与虚拟私有网关</p></figcaption></figure>

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-e2c40625273a36aa58bc2f54be2f2ae4c0dc099a%2Faws-dx-vpc-vgw-2.png?alt=media" alt=""><figcaption><p>选择要关联的 VPC</p></figcaption></figure>

<img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-5961bea9ac389c1aa2f03164b5622f10a99895e1%2FIcon.svg?alt=media&amp;token=a93735da-9464-4c9e-8864-df26ba85d8b3" alt="" data-size="line"><mark style="color:blue;">**注意**</mark>\ <mark style="color:blue;">VGW 通过专线学到的本地路由默认不会自动加入 VPC 路由表。请在对应路由表中启用「路由传播」，或手动添加静态路由，将目标网段的下一跳指向 VGW。</mark>
{% endstep %}

{% step %}
**关联 DXGW 与 VGW**

进入 Direct Connect 服务页面，选择 **Virtual private gateways** > **Direct Connect gateway associations**，将 VGW 关联到已创建的 Direct Connect 网关。

若不填写 **Allowed Prefixes**，默认宣告与该 Direct Connect 关联的整个 VPC 网段；您也可以手动指定需要发布到本地的网段，但不建议宣告主机路由（`/32`）。

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-164aaf9c318decb3eb738ee91ceae87a16364b06%2Faws-dx-dxgw-association-1.png?alt=media" alt=""><figcaption><p>为 VGW 关联 Direct Connect 网关</p></figcaption></figure>

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-665ea30194e1f55b2a640609cf96a7d65a3282ab%2Faws-dx-dxgw-association-2.png?alt=media" alt=""><figcaption><p>设置 Allowed Prefixes</p></figcaption></figure>
{% endstep %}

{% step %}
**接收托管连接（Hosted Connection）**

在您确认 Direct Connect 接入点、VLAN ID 与带宽后，Zenlayer 会为您的账户申请 AWS 托管连接。请登录 AWS 管理控制台，在 Direct Connect 的 **Connections** 页面核对并**接收**该连接。接收后约 3 分钟，即可在该托管连接下继续配置虚拟接口。

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-08c8cba66d7027e9d8e1d18a7644646edebf895e%2Faws-dx-hosted-connection-1.png?alt=media" alt=""><figcaption><p>在 Connections 页面核对待接收的托管连接</p></figcaption></figure>

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-3fb5e68bae576f55150b18e67557e8aa7830bdb0%2Faws-dx-hosted-connection-2.png?alt=media" alt=""><figcaption><p>接收托管连接</p></figcaption></figure>

<img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-5961bea9ac389c1aa2f03164b5622f10a99895e1%2FIcon.svg?alt=media&amp;token=a93735da-9464-4c9e-8864-df26ba85d8b3" alt="" data-size="line"><mark style="color:blue;">**注意**</mark>\ <mark style="color:blue;">接收托管连接后，AWS 将按所选带宽档位开始计收端口占用费。变更或退租时，请同步删除对应的托管连接，以免产生额外费用。计费规则参见</mark> [<mark style="color:purple;">**AWS Direct Connect 定价**</mark>](https://aws.amazon.com/directconnect/pricing/)<mark style="color:blue;">。</mark>
{% endstep %}

{% step %}
**配置虚拟接口（VIF），建立 BGP Peering**

托管连接进入可用状态后，按网络架构创建 **Private VIF** 或 **Transit VIF**，并配置：

* **BGP ASN**：填写您本地路由器的 ASN；Zenlayer 侧 ASN 为 `62610`。
* **BGP 对等 IP**：指定 BGP 会话两端的 IP 地址。
* **BGP 验证密钥**（可选）：设置密码以增强 BGP 会话的安全性。

配置完成后，AWS 约需 5 分钟完成创建。VIF 进入可用状态后，即可与本地设备建立 BGP Peering 并开始路由交换。

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-135d8148d081c57a627f23fa017ca91f76af51c8%2Faws-dx-vif-1.png?alt=media" alt=""><figcaption><p>配置虚拟接口 VIF</p></figcaption></figure>

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-6cb6af82994117b1bc31774b67a7e774a8af20f4%2Faws-dx-vif-2.png?alt=media" alt=""><figcaption><p>VIF 创建完成，BGP Peering 建立</p></figcaption></figure>
{% endstep %}

{% step %}
**配置本地路由器**

在本地路由器上配置与 VIF 一致的 BGP 参数。会话建立后，检查双方路由表：您的路由器应能学到 AWS 宣告的路由，AWS 侧也应学到您宣告的网段。

<figure><img src="https://2318250923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0CBWy7DFFtkhyEC9R4kE%2Fuploads%2Fgit-blob-34756c3315de586727130b5b85909274a6e9038d%2Faws-dx-router-bgp.png?alt=media" alt=""><figcaption><p>本地路由器上的 BGP 会话状态</p></figcaption></figure>
{% endstep %}
{% endstepper %}

## 参考

* [**AWS Direct Connect 常见问题**](https://aws.amazon.com/cn/directconnect/faqs/)
* [**AWS Direct Connect 定价**](https://aws.amazon.com/directconnect/pricing/)
* [**创建虚拟接口**](https://docs.aws.amazon.com/directconnect/latest/UserGuide/create-vif.html)
