

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 管理的前缀分配 Direct Connect 虚拟接口
<a name="prefix-allocations"></a>

您可以管理分配给 Direct Connect 连接上每个虚拟接口的入站路由前缀的数量。使用 AWS 管理控制台或 AWS SDK 查看连接的前缀池，为虚拟接口分配前缀，并根据路由需求的变化调整分配。 AWS CLI

**重要**  
如果虚拟接口上通告的前缀数量超过分配的数量，则该虚拟接口上的 BGP 会话将进入空闲状态（BGP DOWN）。确保您的配额至少与计划宣传的前缀数量一样大。

## 先决条件
<a name="prefix-allocations-prerequisites"></a>

在管理前缀分配之前，请确保您具备以下条件：
+ 活动的 Direct Connect 专用连接或 LAG。
+ 至少一个私有或中转虚拟接口。
+ 调用专线 API 的权限（`directconnect:DescribeConnections`、`directconnect:DescribeVirtualInterfaces`、`directconnect:DescribeDirectConnectGateways`、`directconnect:UpdateVirtualInterfaceAttributes`、`directconnect:CreatePrivateVirtualInterface`、`directconnect:CreateTransitVirtualInterface`）。

## 查看您的连接的前缀池
<a name="prefix-allocations-view-pool"></a>

您可以查看连接的前缀池，以确定有多少可用前缀以及如何在虚拟接口上分配这些前缀。

------
#### [ Console ]

**查看您的连接的前缀池**

1. 打开 [https://console.aws.amazon.com/directconnect/v2/home](https://console.aws.amazon.com/directconnect/v2/home) 控制台，网址为 **Direct Connect**。

1. 在导航窗格中，选择 ** Connections (站点到站点 VPN 连接)**。

1. 选择连接。

1. 在连接详细信息页面上，找到**入站前缀**卡。

1. 查看以下值：**池大小**、**未分配**和已分**配**。IPv4 和 IPv6 值分别显示。

------
#### [ Command line ]

使用[描述连接命令](https://docs.aws.amazon.com/cli/latest/reference/directconnect/describe-connections.html)。

```
aws directconnect describe-connections \
    --connection-id {{dxcon-abc12345}}
```

在响应中，检查以下字段：
+ `prefixPoolSizeIpv4`和 `prefixPoolSizeIpv6` — 池中前缀的总数。
+ `prefixPoolUnallocatedCountIpv4`和 `prefixPoolUnallocatedCountIpv6` — 未分配给虚拟接口的前缀的数量。

------

## 创建虚拟接口时设置前缀分配
<a name="prefix-allocations-create-vif"></a>

您可以在创建虚拟接口时为其设置前缀分配。这会为新的虚拟接口保留连接前缀池的一部分。

------
#### [ Console ]

**在创建虚拟接口时设置前缀分配**

1. 打开 [https://console.aws.amazon.com/directconnect/v2/home](https://console.aws.amazon.com/directconnect/v2/home) 控制台，网址为 **Direct Connect**。

1. 在导航窗格中，选择 **Virtual Interfaces**。

1. 选择 **Create virtual interface (创建虚拟接口)**。

1. 配置虚拟接口设置，包括类型、VLAN 和 BGP ASN。

1. 在**入站前缀分配**部分中，输入要分配的 IPv4 和 IPv6 前缀的数量。

1. 选择 **Create virtual interface (创建虚拟接口)**。

------
#### [ Command line ]

使用 “[创建私有虚拟接口](https://docs.aws.amazon.com/cli/latest/reference/directconnect/create-private-virtual-interface.html)” 命令。以下示例使用前缀分配创建私有虚拟接口。

```
aws directconnect create-private-virtual-interface \
    --connection-id {{dxcon-abc12345}} \
    --new-private-virtual-interface '{
        "virtualInterfaceName": "{{my-private-vif}}",
        "vlan": {{101}},
        "asn": {{65000}},
        "directConnectGatewayId": "{{d2113d06-a0d8-476b-91a7-8555d9973d12}}",
        "prefixPoolAllocatedCountIpv4": {{500}},
        "prefixPoolAllocatedCountIpv6": {{100}}
    }'
```

------

## 更新现有虚拟接口上的前缀分配
<a name="prefix-allocations-update"></a>

您可以更新现有虚拟接口上的前缀分配，以增加或减少为该接口保留的前缀数量。

------
#### [ Console ]

**更新虚拟接口上的前缀分配**

1. 打开 [https://console.aws.amazon.com/directconnect/v2/home](https://console.aws.amazon.com/directconnect/v2/home) 控制台，网址为 **Direct Connect**。

1. 在导航窗格中，选择 **Virtual Interfaces**。

1. 选择要更新的虚拟接口。

1. 选择**编辑**。

1. 更新 ** IPv4 前缀分配**值、** IPv6 前缀分配**值或两者。

1. 选择 “**更新虚拟接口” **。

------
#### [ Command line ]

使用[更新虚拟接口属性](https://docs.aws.amazon.com/cli/latest/reference/directconnect/update-virtual-interface-attributes.html)命令。

```
aws directconnect update-virtual-interface-attributes \
    --virtual-interface-id {{dxvif-abc12345}} \
    --prefix-pool-allocated-count-ipv4 {{500}} \
    --prefix-pool-allocated-count-ipv6 {{100}}
```

------

## 查看 Direct Connect 网关前缀分配总数
<a name="prefix-allocations-view-dxgw"></a>

您可以查看连接到 Direct Connect 网关的所有虚拟接口的前缀分配总数。

------
#### [ Console ]

**查看 Direct Connect 网关前缀分配总数**

1. 打开 [https://console.aws.amazon.com/directconnect/v2/home](https://console.aws.amazon.com/directconnect/v2/home) 控制台，网址为 **Direct Connect**。

1. 在导航窗格中，选择 **Direct Connect Gateways**。

1. 选择您的网关。

1. 在网关详细信息页面上，查看前缀池分配**总**值。

------
#### [ Command line ]

使用[描述直接连接网关命令](https://docs.aws.amazon.com/cli/latest/reference/directconnect/describe-direct-connect-gateways.html)。

```
aws directconnect describe-direct-connect-gateways \
    --direct-connect-gateway-id {{d2113d06-a0d8-476b-91a7-8555d9973d12}}
```

在响应中，检查该`totalPrefixPoolAllocations`字段。

------

## 验证分配变更
<a name="prefix-allocations-expected-results"></a>

更新前缀分配后，新值将立即生效。只要通告的前缀数量不超过新的分配，BGP 会话就会保持运行状态。API 拒绝将分配减少到 VIF 当前使用的前缀数量以下的请求。

## 问题排查
<a name="prefix-allocations-troubleshooting"></a>

以下是您在管理前缀分配时可能遇到的常见问题。

添加前缀后 BGP 会话关闭  
通告的前缀数量超过了分配的数量。使用 `UpdateVirtualInterfaceAttributes` API 或控制台增加分配。

无法减少分配  
您不能将 VIF 的分配值减少到低于当前使用的前缀数量以下。首先减少本地设备公布的前缀数量，然后减少分配。

无法增加配额  
连接的前缀池可能已完全分配。检查连接上的`prefixPoolUnallocatedCountIpv4`和`prefixPoolUnallocatedCountIpv6`值。您可能需要先减少其他虚拟接口的分配。

专线网关总数超过 10,000  
连接到单个专线网关的虚拟接口上的所有 IPv4 和 IPv6 组合分配的总和不能超过 10,000。减少在其他虚拟接口上的分配或使用第二个网关。