

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

# 將彈性 IP 位址與執行個體建立關聯
<a name="working-with-eips"></a>

配置彈性 IP 地址之後，您可以將其與 AWS 資源建立關聯，例如 EC2 執行個體、NAT 閘道或 Network Load Balancer。若要稍後將彈性 IP 地址與不同的 AWS 資源建立關聯，您可以取消其與其目前資源的關聯，然後將其與新資源建立關聯。

**Topics**
+ [配置彈性 IP 位址](#using-instance-addressing-eips-allocating)
+ [建立彈性 IP 位址的關聯](#using-instance-addressing-eips-associating)
+ [取消彈性 IP 位址的關聯](#using-instance-addressing-eips-associating-different)

## 配置彈性 IP 位址
<a name="using-instance-addressing-eips-allocating"></a>

配置用於某區域的彈性 IP 位址。無論是處於使用中 (與資源關聯，例如 EC2 執行個體) 還是閒置狀態 (已在帳戶中建立但未關聯)，所有彈性 IP 位址都會產生費用。

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

**配置彈性 IP 地址**

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

1. 在導覽窗格中，於 **Network & Security (網路與安全)** 中，選擇 **Elastic IPs (彈性 IP)**。

1. 選擇 **Allocate Elastic IP address (配置彈性 IP 位址)**。

1. (選用) 配置彈性 IP 地址 (EIP) 時，您可以選擇要配置 EIP 的**網路邊界群組**。網路邊界群組是可用區域 (AZs)、本機區域或 Wavelength 區域的集合，可從中 AWS 公告公有 IP 地址。Local Zones 和 Wavelength Zones 的網路邊界群組可能與區域中AZs 不同，以確保 AWS 網路和存取這些區域中資源的客戶之間的最低延遲或實體距離。
**重要**  
您必須在與 EIP 相關聯的 AWS 資源相同的網路邊界群組中配置 EIP。一個網路邊界群組中的 EIP 只能在該網路邊界群組中的區域中進行公告，而不能在其他網路邊界群組所代表的任何其他區域中進行公告。

   如果您已啟用 Local Zones 或 Wavelength Zones (如需詳細資訊，請參閱[啟用 Local Zone](https://docs.aws.amazon.com/local-zones/latest/ug/getting-started.html#getting-started-find-local-zone) 或[啟用 Wavelength Zones](https://docs.aws.amazon.com//wavelength/latest/developerguide/get-started-wavelength.html#enable-zone-group))，您可以為 AZ、Local Zones 或 Wavelength Zones 選擇網路邊界群組。請謹慎選擇網路邊界群組，因為 EIP 及其關聯的 AWS 資源必須位於相同的網路邊界群組中。您可以使用 EC2 主控台檢視可用區域、Local Zones 或 Wavelength Zones 所在的網路邊界群組。一般而言，區域中的所有可用區域屬於相同的網路邊界群組，而 Local Zones 或 Wavelength Zones 則屬於其各自的網路邊界群組。

   如果您沒有啟用 Local Zones 或 Wavelength Zones，則當您配置 EIP 時，代表該區域所有 AZ 的網路邊界群組 (例如 `us-west-2`) 會為您預先定義，且您無法予以變更。這表示您配置給此網路邊界群組的 EIP 會在您所在區域的所有 AZ 中進行公告。

1. 對於**公有 IPv4 地址集區**，請選擇下列其中一項：
   + **Amazon 的 IPv4 地址集區**—若您要從 Amazon IPv4 地址集區配置一個 IPv4 地址。
   + **您帶入 AWS 帳戶的公有 IPv4 位址** - 如果您想要從您的 AWS 帳戶中的 IP 位址集區中指派不連續 (非連續) 的公用 IPv4 位址。如果您沒有任何 IP 位址集區，則會停用此選項。如需將您自己的 IP 地址範圍帶入 AWS 帳戶的詳細資訊，請參閱 [將自有 IP 位址 (BYOIP) 用於 Amazon EC2](ec2-byoip.md)。
   + **客戶擁有的 IPv4 地址集**區 - 如果您想要從內部部署網路建立的集區配置 IPv4 地址，以便與 AWS Outpost 搭配使用。如果您沒有 AWS Outpost，則會停用此選項。
   + **使用 IPAM IPv4 集區配置**：如果您想要從 IPAM 集區中的連續公有 IPv4 區塊配置循序彈性 IP 位址。配置循序彈性 IP 位址可大幅降低安全存取控制清單的管理開銷，並簡化企業在 上擴展的 IP 位址配置和追蹤 AWS。如需詳細資訊，請參閱[「Amazon VPC IPAM 使用者指南」**中的從 IPAM 集區配置循序彈性 IP 位址](https://docs.aws.amazon.com/vpc/latest/ipam/tutorials-eip-pool.html)。

1. (選用) 若要新增標籤，請選擇**新增標籤**，然後輸入標籤金鑰和標籤值。

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

**配置彈性 IP 位址**  
使用 [allocate-address](https://docs.aws.amazon.com/cli/latest/reference/ec2/allocate-address.html) AWS CLI 命令。

在以下範圍中，Amazon EC2 會從 Amazon 的地址集區中選取地址。

```
aws ec2 allocate-address
```

在下列範例中，Amazon EC2 會從您使用 AWS BYOIP 帶到 的指定集區中選取地址。

```
aws ec2 allocate-address \
    --public-ipv4-pool ipv4pool-ec2-012345abcdef67890
```

下列範例指定來自指定 IPv4 IPAM 集區的地址。

```
aws ec2 allocate-address \
    --ipam-pool-id ipam-pool-1234567890abcdef0 \
    --address 192.0.2.0
```

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

**配置彈性 IP 位址**  
使用 [New-EC2Address](https://docs.aws.amazon.com/powershell/latest/reference/items/New-EC2Address.html) cmdlet。

在以下範圍中，Amazon EC2 會從 Amazon 的地址集區中選取地址。

```
New-EC2Address
```

在下列範例中，Amazon EC2 會從您使用 AWS BYOIP 帶到 的指定集區中選取地址。

```
New-EC2Address `
    -PublicIpv4Pool ipv4pool-ec2-012345abcdef67890
```

下列範例指定來自指定 IPv4 IPAM 集區的地址。

```
New-EC2Address `
    -IpamPoolId ipam-pool-1234567890abcdef0 `
    -Address 192.0.2.0
```

------

## 建立彈性 IP 位址的關聯
<a name="using-instance-addressing-eips-associating"></a>

如果您想要將彈性 IP 位址與執行個體建立關聯來啟用與網際網路通訊的功能，您也必須確定執行個體位於公有子網路中。如需詳細資訊，請參閱「Amazon VPC 使用者指南」**中的[使用網際網路閘道啟用網際網路存取](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html)。

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

**建立彈性 IP 位址與執行個體的關聯**

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

1. 在導覽窗格中，選擇 **Elastic IPs (彈性 IP)**。

1. 選取要關聯的彈性 IP 位址並依序選取 **Actions (動作)**、**Associate Elastic IP address (關聯彈性 IP 位址)**。

1. 對於 **Resource type** (資源類型)，選擇 **Instance** (執行個體)。

1. 例如，選擇要與彈性 IP 位址建立關聯的執行個體。您也可以輸入文字來搜尋特定執行個體。

1. (選用) 對於 **Private IP address (私人 IP 位址)**，指定要與彈性 IP 位址建立關聯的私人 IP 位址。

1. 選擇 **Associate** (關聯)。

**建立彈性 IP 位址與網路介面的關聯。**

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

1. 在導覽窗格中，選擇 **Elastic IPs (彈性 IP)**。

1. 選取要關聯的彈性 IP 位址並依序選取 **Actions (動作)**、**Associate Elastic IP address (關聯彈性 IP 位址)**。

1. 對於**資源類型**，選擇 **Network interface** (網路介面)。

1. 在 **Network interface (網路介面)** 中，選擇要與彈性 IP 位址建立關聯的網路介面。您也可以輸入文字來搜尋特定網路介面。

1. (選用) 對於 **Private IP address (私人 IP 位址)**，指定要與彈性 IP 位址建立關聯的私人 IP 位址。

1. 選擇 **Associate** (關聯)。

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

**建立彈性 IP 位址的關聯**  
使用 [associate-address](https://docs.aws.amazon.com/cli/latest/reference/ec2/associate-address.html) AWS CLI 命令。

```
aws ec2 associate-address \
    --instance-id i-0b263919b6498b123 \
    --allocation-id eipalloc-64d5890a
```

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

**建立彈性 IP 位址的關聯**  
使用 [Register-EC2Address](https://docs.aws.amazon.com/powershell/latest/reference/items/Register-EC2Address.html) cmdlet。

```
Register-EC2Address `
    -InstanceId i-0b263919b6498b123 `
    -AllocationId eipalloc-64d5890a
```

------

## 取消彈性 IP 位址的關聯
<a name="using-instance-addressing-eips-associating-different"></a>

您可以隨時解除彈性 IP 位址與執行個體或網路介面的關聯。解除與彈性 IP 位址的關聯後，您可以將它與其他資源建立關聯。

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

**解除關聯並重新關聯彈性 IP 位址**

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

1. 在導覽窗格中，選擇 **Elastic IPs (彈性 IP)**。

1. 選取要解除彈性 IP 位址的關聯，請依序選取 **Actions (動作)**、**Disassociate Elastic IP address (解除彈性 IP 位址的關聯)**。

1. 選擇 **Disassociate (取消關聯)**。

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

**取消與彈性 IP 位址的關聯**  
使用 [disassociate-address](https://docs.aws.amazon.com/cli/latest/reference/ec2/disassociate-address.html) AWS CLI 命令。

```
aws ec2 disassociate-address --association-id eipassoc-12345678
```

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

**取消與彈性 IP 位址的關聯**  
使用 [Unregister-EC2Address](https://docs.aws.amazon.com/powershell/latest/reference/items/Unregister-EC2Address.html) cmdlet。

```
Unregister-EC2Address -AssociationId eipassoc-12345678
```

------