

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 管理 Direct Connect 虛擬介面的字首配置
<a name="prefix-allocations"></a>

您可以管理配置給 Direct Connect 連線上每個虛擬界面的傳入路由字首數量。使用 AWS 管理主控台 AWS CLI或 AWS SDKs來檢視連線的字首集區、將字首配置到虛擬介面，以及隨著路由需求變更調整配置。

**重要**  
如果虛擬介面上的公告字首數量超過配置的計數，則該虛擬介面上的 BGP 工作階段會進入閒置狀態 (BGP DOWN)。確保您的配置至少與您計劃公告的字首數量一樣大。

## 先決條件
<a name="prefix-allocations-prerequisites"></a>

在管理字首配置之前，請確定您有下列項目：
+ 作用中的 Direct Connect 專用連線或 LAG。
+ 至少一個私有或傳輸虛擬介面。
+ 呼叫 Direct Connect APIs許可 (`directconnect:DescribeConnections`、`directconnect:DescribeVirtualInterfaces`、`directconnect:DescribeDirectConnectGateways`、`directconnect:UpdateVirtualInterfaceAttributes`、`directconnect:CreatePrivateVirtualInterface`、`directconnect:CreateTransitVirtualInterface`)。

## 檢視連線的字首集區
<a name="prefix-allocations-view-pool"></a>

您可以檢視連線的字首集區，以判斷有多少字首可用，以及如何在虛擬界面之間配置。

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

**檢視連線的字首集區**

1. 在 https：//[https://console.aws.amazon.com/directconnect/v2/home](https://console.aws.amazon.com/directconnect/v2/home) 開啟 **Direct Connect**主控台。

1. 在導覽窗格中，選擇 **Connections** (連線)。

1. 選取連線。

1. 在連線詳細資訊頁面上，找到**傳入字首**卡。

1. 檢閱下列值：**集區大小**、**未配置**和**已配置**。IPv4 和 IPv6 值會分別顯示。

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

使用 [describe-connections](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：//[https://console.aws.amazon.com/directconnect/v2/home](https://console.aws.amazon.com/directconnect/v2/home) 開啟 **Direct Connect**主控台。

1. 在導覽窗格中，選擇 **Virtual Interfaces** (虛擬介面)。

1. 選擇**建立虛擬介面**。

1. 設定虛擬介面設定，包括類型、VLAN 和 BGP ASN。

1. 在**傳入字首配置**區段中，輸入要配置的 IPv4 和 IPv6 字首數量。

1. 選擇**建立虛擬介面**。

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

使用 [create-private-virtual-interface](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：//[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 ]

使用 [update-virtual-interface-attributes](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：//[https://console.aws.amazon.com/directconnect/v2/home](https://console.aws.amazon.com/directconnect/v2/home) 開啟 **Direct Connect**主控台。

1. 在導覽窗格中，選擇 **Direct Connect Gateways (Direct Connect 閘道)**。

1. 選取您的閘道。

1. 在閘道詳細資訊頁面上，檢閱**總字首集區配置**值。

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

使用 [describe-direct-connect-gateways](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`值。您可能需要先減少其他虛擬介面的配置。

Direct Connect 閘道總計超過 10，000  
連接至單一 Direct Connect 閘道之虛擬介面的所有合併 IPv4 和 IPv6 配置總和不得超過 10，000。減少其他虛擬介面的配置或使用第二個閘道。