

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

# 網路介面字首
<a name="work-with-prefixes"></a>

當您將字首指派給網路介面時，可以選擇讓我們自動指派字首，還是指定自訂字首。如果您讓我們自動指派字首，且網路介面的子網路具有類型 `prefix` 的子網路 CIDR 預留，我們會從子網路 CIDR 預留中選取字首。否則，我們會從子網路 CIDR 範圍中進行選取。

**Topics**
+ [在建立網路介面期間指派字首](#assign-auto-creation)
+ [為現有的網路介面指派字首](#assign-auto-existing)
+ [從網路介面移除字首](#unassign-prefix)

## 在建立網路介面期間指派字首
<a name="assign-auto-creation"></a>

您可以在建立網路介面時指派自動或自訂字首。

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

**在建立網路介面期間指派自動字首**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇 **Network Interfaces (網路介面)**。

1. 選擇 **Create network interface** (建立網路介面)。

1. 指定網路介面的描述，選取要在其中建立網路介面的子網路，然後設定私有 IPv4 和 IPv6 地址。

1. 展開 **Advanced settings** (進階設定)。

1. 對於 **IPv4 字首委派**，請執行下列其中一項操作：
   + 若要自動指派 IPv4 字首，選擇**自動指派**。然後對於 **IPv4 字首的數目**，指定要指派的字首數目。
   + 若要指派特定的 IPv4 字首，請選擇**自訂**。然後選擇**新增字首**，並輸入要使用的字首。

1. 對於 **IPv6 字首委派**，請執行下列其中一項操作：
   + 若要自動指派 IPv6 字首，選擇**自動指派**。然後對於 **IPv6 字首的數目**，指定要指派的字首數目。
   + 若要指派特定的 IPv6 字首，請選擇**自訂**。然後選擇**新增字首**，並輸入要使用的字首。
**注意**  
**IPv6 prefix delegation** (IPv6 字首委派) 僅在為 IPv6 啟用選定的子網才會出現。

1. 選取要與網路介面建立關聯的安全群組，並視需要指派資源標籤。

1. 選擇 **Create network interface** (建立網路介面)。

------
#### [ AWS CLI ]

**在建立網路介面期間指派自動 IPv4 字首**  
使用 [create-network-interface](https://docs.aws.amazon.com/cli/latest/reference/ec2/create-network-interface.html) 命令，並將 `--ipv4-prefix-count` 設定為 AWS 要指派的 IPv4 字首數目。在下列範例中， AWS 會指派一個 IPv4 字首。

```
aws ec2 create-network-interface \
    --subnet-id {{subnet-047cfed18eEXAMPLE}} \
    --description "{{IPv4 automatic example}}" \
    --ipv4-prefix-count {{1}}
```

**在建立網路介面期間指派特定的 IPv4 字首**  
使用 [create-network-interface](https://docs.aws.amazon.com/cli/latest/reference/ec2/create-network-interface.html) 命令，並將 `--ipv4-prefixes` 設定為字首。 AWS 會從此範圍中選取 IPv4 地址。在下列範例中，字首 CIDR 是 10.0.0.208/28。

```
aws ec2 create-network-interface \
    --subnet-id {{subnet-047cfed18eEXAMPLE}} \
    --description "{{IPv4 manual example}}" \
    --ipv4-prefixes Ipv4Prefix={{10.0.0.208/28}}
```

**在建立網路介面期間指派自動 IPv6 字首**  
使用 [create-network-interface](https://docs.aws.amazon.com/cli/latest/reference/ec2/create-network-interface.html) 命令，並將 `--ipv6-prefix-count` 設定為 AWS 要指派的 IPv6 字首數目。在下列範例中， AWS 會指派一個 IPv6 字首。

```
aws ec2 create-network-interface \
    --subnet-id {{subnet-047cfed18eEXAMPLE}} \
    --description "{{IPv6 automatic example}}" \
    --ipv6-prefix-count {{1}}
```

**在建立網路介面期間指派特定的 IPv6 字首**  
使用 [create-network-interface](https://docs.aws.amazon.com/cli/latest/reference/ec2/create-network-interface.html) 命令，並將 `--ipv6-prefixes` 設定為字首。 AWS 會從此範圍中選取 IPv6 地址。在下列範例中，字首 CIDR 是 2600:1f13:fc2:a700:1768::/80。

```
aws ec2 create-network-interface \
    --subnet-id {{subnet-047cfed18eEXAMPLE}} \
    --description "{{IPv6 manual example}}" \
    --ipv6-prefixes Ipv6Prefix={{2600:1f13:fc2:a700:1768::/80}}
```

------
#### [ PowerShell ]

**在建立網路介面期間指派自動 IPv4 字首**  
使用 [New-EC2NetworkInterface](https://docs.aws.amazon.com/powershell/latest/reference/items/New-EC2NetworkInterface.html) cmdlet，並將 `Ipv4PrefixCount` 設定為 AWS 要指派的 IPv4 字首數量。在下列範例中， AWS 會指派一個 IPv4 字首。

```
New-EC2NetworkInterface `
    -SubnetId '{{subnet-047cfed18eEXAMPLE}}' `
    -Description '{{IPv4 automatic example}}' `
    -Ipv4PrefixCount {{1}}
```

**在建立網路介面期間指派特定的 IPv4 字首**  
使用 [New-EC2NetworkInterface](https://docs.aws.amazon.com/powershell/latest/reference/items/New-EC2NetworkInterface.html) cmdlet 並`Ipv4Prefix`設定為字首。從此範圍 AWS 中選取 IPv4 地址。在下列範例中，字首 CIDR 是 10.0.0.208/28。

```
Import-Module AWS.Tools.EC2
New-EC2NetworkInterface `
    -SubnetId '{{subnet-047cfed18eEXAMPLE}}' `
    -Description '{{IPv4 manual example}}' `
    -Ipv4Prefix (New-Object `
        -TypeName Amazon.EC2.Model.Ipv4PrefixSpecificationRequest `
        -Property @{Ipv4Prefix = '{{10.0.0.208/28}}'})
```

**在建立網路介面期間指派自動 IPv6 字首**  
使用 [New-EC2NetworkInterface](https://docs.aws.amazon.com/powershell/latest/reference/items/New-EC2NetworkInterface.html) cmdlet，並將 `Ipv6PrefixCount` 設定為 AWS 要指派的 IPv6 字首數量。在下列範例中， AWS 會指派一個 IPv6 字首。

```
New-EC2NetworkInterface `
    -SubnetId '{{subnet-047cfed18eEXAMPLE}}' `
    -Description '{{IPv6 automatic example}}' `
    -Ipv6PrefixCount {{1}}
```

**在建立網路介面期間指派特定的 IPv6 字首**  
使用 [New-EC2NetworkInterface](https://docs.aws.amazon.com/powershell/latest/reference/items/New-EC2NetworkInterface.html) cmdlet 並`Ipv6Prefixes`設定為字首。從此範圍 AWS 中選取 IPv6 地址。在下列範例中，字首 CIDR 是 2600:1f13:fc2:a700:1768::/80。

```
Import-Module AWS.Tools.EC2
New-EC2NetworkInterface `
    -SubnetId '{{subnet-047cfed18eEXAMPLE}}' `
    -Description '{{IPv6 manual example}}' `
    -Ipv6Prefix (New-Object `
        -TypeName Amazon.EC2.Model.Ipv6PrefixSpecificationRequest `
        -Property @{Ipv6Prefix = '{{2600:1f13:fc2:a700:1768::/80}}'})
```

------

## 為現有的網路介面指派字首
<a name="assign-auto-existing"></a>

您可以為現有網路介面指派自動或自訂字首。

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

**將自動字首指派給現有網路介面**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇 **Network Interfaces** (網路介面)。

1. 選取要指派字首的網路介面，然後選取 **Actions** (動作)、**Manage prefixes** (管理字首)。

1. 對於 **IPv4 字首委派**，請執行下列其中一項操作：
   + 若要自動指派 IPv4 字首，選擇**自動指派**。然後對於 **IPv4 字首的數目**，指定要指派的字首數目。
   + 若要指派特定的 IPv4 字首，請選擇**自訂**。然後選擇**新增字首**，並輸入要使用的字首。

1. 對於 **IPv6 字首委派**，請執行下列其中一項操作：
   + 若要自動指派 IPv6 字首，選擇**自動指派**。然後對於 **IPv6 字首的數目**，指定要指派的字首數目。
   + 若要指派特定的 IPv6 字首，請選擇**自訂**。然後選擇**新增字首**，並輸入要使用的字首。
**注意**  
**IPv6 prefix delegation** (IPv6 字首委派) 僅在為 IPv6 啟用選定的子網才會出現。

1. 選擇**儲存**。

------
#### [ AWS CLI ]

使用 [assign-ipv6-addresses](https://docs.aws.amazon.com/cli/latest/reference/ec2/assign-ipv6-addresses.html) 命令來指派 IPv6 字首，並使用 [assign-private-ip-addresses](https://docs.aws.amazon.com/cli/latest/reference/ec2/assign-private-ip-addresses.html) 命令將 IPv4 字首指派給現有的網路介面。

**將自動 IPv4 字首指派給現有網路介面**  
使用 [assign-private-ip-addresses](https://docs.aws.amazon.com/cli/latest/reference/ec2/assign-private-ip-addresses.html) 命令，並將 `--ipv4-prefix-count` 設定為 AWS 要指派的 IPv4 字首數目。在下列範例中， AWS 會指派一個 IPv4 字首。

```
aws ec2 assign-private-ip-addresses \
    --network-interface-id {{eni-081fbb4095EXAMPLE}} \
    --ipv4-prefix-count {{1}}
```

**若要將特定 IPv4 字首指派給現有的網路介面**  
使用 [assign-private-ip-addresses](https://docs.aws.amazon.com/cli/latest/reference/ec2/assign-private-ip-addresses.html) 命令並將 `--ipv4-prefixes` 設定為字首。 AWS 會從此範圍選取 IPv4 位址。在下列範例中，字首 CIDR 是 10.0.0.208/28。

```
aws ec2 assign-private-ip-addresses \
    --network-interface-id {{eni-081fbb4095EXAMPLE}} \
    --ipv4-prefixes {{10.0.0.208/28}}
```

**將自動 IPv6 字首指派給現有網路介面**  
使用 [assign-ipv6-addresses](https://docs.aws.amazon.com/cli/latest/reference/ec2/assign-ipv6-addresses.html) 命令，並將 `--ipv6-prefix-count` 設定為 AWS 要指派的 IPv6 字首數目。在下列範例中， AWS 會指派一個 IPv6 字首。

```
aws ec2 assign-ipv6-addresses \
    --network-interface-id {{eni-00d577338cEXAMPLE}} \
    --ipv6-prefix-count {{1}}
```

**若要將特定 IPv6 字首指派給現有的網路介面**  
使用 [assign-ipv6-addresses](https://docs.aws.amazon.com/cli/latest/reference/ec2/assign-ipv6-addresses.html) 命令並`--ipv6-prefixes`設定為字首。從此範圍 AWS 中選取 IPv6 地址。在下列範例中，字首 CIDR 是 2600:1f13:fc2:a700:18bb::/80。

```
aws ec2 assign-ipv6-addresses \
    --network-interface-id {{eni-00d577338cEXAMPLE}} \
    --ipv6-prefixes {{2600:1f13:fc2:a700:18bb::/80}}
```

------
#### [ PowerShell ]

**將自動 IPv4 字首指派給現有網路介面**  
使用 [Register-EC2PrivateIpAddress](https://docs.aws.amazon.com/powershell/latest/reference/items/Register-EC2PrivateIpAddress.html) cmdlet，並將 `Ipv4PrefixCount` 設定為 AWS 要指派的 IPv4 字首數目。在下列範例中， AWS 會指派一個 IPv4 字首。

```
Register-EC2PrivateIpAddress `
    -NetworkInterfaceId '{{eni-00d577338cEXAMPLE}}' `
    -Ipv4PrefixCount {{1}}
```

**若要將特定 IPv4 字首指派給現有的網路介面**  
使用 [Register-EC2PrivateIpAddress](https://docs.aws.amazon.com/powershell/latest/reference/items/Register-EC2PrivateIpAddress.html) cmdlet 並`Ipv4Prefix`設定為字首。從此範圍 AWS 中選取 IPv4 地址。在下列範例中，字首 CIDR 是 10.0.0.208/28。

```
Register-EC2PrivateIpAddress `
    -NetworkInterfaceId '{{eni-00d577338cEXAMPLE}}' `
    -Ipv4Prefix '{{10.0.0.208/28}}'
```

**將自動 IPv6 字首指派給現有網路介面**  
使用 [Register-EC2Ipv6AddressList](https://docs.aws.amazon.com/powershell/latest/reference/items/Register-EC2Ipv6AddressList.html) cmdlet，並將 `Ipv6PrefixCount` 設定為 AWS 要指派的 IPv4 字首數目。在下列範例中， AWS 會指派一個 IPv6 字首。

```
Register-EC2Ipv6AddressList `
    -NetworkInterfaceId '{{eni-00d577338cEXAMPLE}}' `
    -Ipv6PrefixCount {{1}}
```

**若要將特定 IPv6 字首指派給現有的網路介面**  
使用 [Register-EC2Ipv6AddressList](https://docs.aws.amazon.com/powershell/latest/reference/items/Register-EC2Ipv6AddressList.html) cmdlet 並`Ipv6Prefix`設定為字首。從此範圍 AWS 中選取 IPv6 地址。在下列範例中，字首 CIDR 是 2600:1f13:fc2:a700:18bb::/80。

```
Register-EC2Ipv6AddressList `
    -NetworkInterfaceId '{{eni-00d577338cEXAMPLE}}' `
    -Ipv6Prefix '{{2600:1f13:fc2:a700:18bb::/80}}'
```

------

## 從網路介面移除字首
<a name="unassign-prefix"></a>

您可以從現有的網路介面移除字首。

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

**從網路介面移除字首**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇 **Network Interfaces (網路介面)**。

1. 選取網路介面。

1. 選擇**動作**、**管理字首**。

1. 對於 **IPv4 字首委派**，若要移除特定字首，請選擇要移除字首旁的**取消指派**。若要移除所有字首，請選擇**不指派**。

1. 對於 **IPv6 字首委派**，若要移除特定字首，請選擇要移除字首旁的**取消指派**。若要移除所有字首，請選擇**不指派**。
**注意**  
**IPv6 prefix delegation** (IPv6 字首委派) 僅在為 IPv6 啟用選定的子網才會出現。

1. 選擇**儲存**。

------
#### [ AWS CLI ]

您可以使用 [unassign-ipv6-addresses](https://docs.aws.amazon.com/cli/latest/reference/ec2/unassign-ipv6-addresses.html) 命令來移除 IPv6 字首，並使用 [unassign-private-ip-address](https://docs.aws.amazon.com/cli/latest/reference/ec2/unassign-private-ip-addresses.html) 命令，從現有的網路介面移除 IPv4 字首。

**從網路介面移除 IPv4 字首**  


使用 [unassign-private-ip-address](https://docs.aws.amazon.com/cli/latest/reference/ec2/unassign-private-ip-addresses.html) 命令，並將 `--ipv4-prefix` 設定為字首 CIDR 以移除。

```
aws ec2 unassign-private-ip-addresses \
    --network-interface-id {{eni-081fbb4095EXAMPLE}} \
    --ipv4-prefixes {{10.0.0.176/28}}
```

**從網路介面移除 IPv6 字首**  
使用 [unassign-ipv6-addresses](https://docs.aws.amazon.com/cli/latest/reference/ec2/unassign-ipv6-addresses.html) 命令，並將 `--ipv6-prefix` 設定為字首 CIDR 以移除。

```
aws ec2 unassign-ipv6-addresses \
    --network-interface-id {{eni-00d577338cEXAMPLE}} \
    --ipv6-prefix {{2600:1f13:fc2:a700:18bb::/80}}
```

------
#### [ PowerShell ]

**從網路介面移除 IPv4 字首**  
使用 [Unregister-EC2PrivateIpAddress](https://docs.aws.amazon.com/powershell/latest/reference/items/Unregister-EC2PrivateIpAddress.html) cmdlet，並將 `Ipv4Prefix` 設定字首 CIDR 以移除。

```
Unregister-EC2PrivateIpAddress `
    -NetworkInterfaceId '{{eni-00d577338cEXAMPLE}}' `
    -Ipv4Prefix '{{10.0.0.208/28}}'
```

**從網路介面移除 IPv6 字首**  
使用 [Unregister-EC2Ipv6AddressList](https://docs.aws.amazon.com/powershell/latest/reference/items/Unregister-EC2Ipv6AddressList.html) cmdlet，並將 `Ipv6Prefix` 設定字首 CIDR 以移除。

```
Unregister-EC2Ipv6AddressList `
    -NetworkInterfaceId '{{eni-00d577338cEXAMPLE}}' `
    -Ipv6Prefix '{{2600:1f13:fc2:a700:18bb::/80}}'
```

------