選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

AssignPrivateIpAddresses - Amazon Elastic Compute Cloud
此頁面尚未翻譯為您的語言。 請求翻譯

AssignPrivateIpAddresses

Assigns the specified secondary private IP addresses to the specified network interface.

You can specify specific secondary IP addresses, or you can specify the number of secondary IP addresses to be automatically assigned from the subnet's CIDR block range. The number of secondary IP addresses that you can assign to an instance varies by instance type. For more information about Elastic IP addresses, see Elastic IP Addresses in the Amazon EC2 User Guide.

When you move a secondary private IP address to another network interface, any Elastic IP address that is associated with the IP address is also moved.

Remapping an IP address is an asynchronous operation. When you move an IP address from one network interface to another, check network/interfaces/macs/mac/local-ipv4s in the instance metadata to confirm that the remapping is complete.

You must specify either the IP addresses or the IP address count in the request.

You can optionally use Prefix Delegation on the network interface. You must specify either the IPv4 Prefix Delegation prefixes, or the IPv4 Prefix Delegation count. For information, see Assigning prefixes to network interfaces in the Amazon EC2 User Guide.

Request Parameters

The following parameters are for this specific action. For more information about required and optional parameters that are common to all actions, see Common Query Parameters.

AllowReassignment

Indicates whether to allow an IP address that is already assigned to another network interface or instance to be reassigned to the specified network interface.

Type: Boolean

Required: No

Ipv4Prefix.N

One or more IPv4 prefixes assigned to the network interface. You can't use this option if you use the Ipv4PrefixCount option.

Type: Array of strings

Required: No

Ipv4PrefixCount

The number of IPv4 prefixes that AWS automatically assigns to the network interface. You can't use this option if you use the Ipv4 Prefixes option.

Type: Integer

Required: No

NetworkInterfaceId

The ID of the network interface.

Type: String

Required: Yes

PrivateIpAddress.N

The IP addresses to be assigned as a secondary private IP address to the network interface. You can't specify this parameter when also specifying a number of secondary IP addresses.

If you don't specify an IP address, Amazon EC2 automatically selects an IP address within the subnet range.

Type: Array of strings

Required: No

SecondaryPrivateIpAddressCount

The number of secondary IP addresses to assign to the network interface. You can't specify this parameter when also specifying private IP addresses.

Type: Integer

Required: No

Response Elements

The following elements are returned by the service.

assignedIpv4PrefixSet

The IPv4 prefixes that are assigned to the network interface.

Type: Array of Ipv4PrefixSpecification objects

assignedPrivateIpAddressesSet

The private IP addresses assigned to the network interface.

Type: Array of AssignedPrivateIpAddress objects

networkInterfaceId

The ID of the network interface.

Type: String

requestId

The ID of the request.

Type: String

Errors

For information about the errors that are common to all actions, see Common client error codes.

Examples

Example 1

This example assigns two secondary private IP addresses (10.0.2.1 and 10.0.2.11) to the specified network interface.

Sample Request

https://ec2.amazonaws.com/?Action=AssignPrivateIpAddresses &NetworkInterfaceId=eni-d83388b1 &PrivateIpAddress.1=10.0.2.1 &PrivateIpAddress.2=10.0.2.11 &AUTHPARAMS

Sample Response

<AssignPrivateIpAddressesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>3fb591ba-558c-48f8-ae6b-c2f9d6d06425</requestId> <networkInterfaceId>eni-01d32da61c165ac3e</networkInterfaceId> <assignedPrivateIpAddressesSet> <item> <privateIpAddress>10.2.2.1</privateIpAddress> </item> <item> <privateIpAddress>10.2.2.11</privateIpAddress> </item> </assignedPrivateIpAddressesSet> <return>true</return> </AssignPrivateIpAddressesResponse>

Example 2

This example assigns two secondary private IP addresses to the specified network interface. Amazon EC2 automatically assigns these IP addresses from the available IP addresses within the subnet's CIDR block range.

Sample Request

https://ec2.amazonaws.com/?Action=AssignPrivateIpAddresses &NetworkInterfaceId=eni-d83388b1 &SecondaryPrivateIpAddressCount=2 &AUTHPARAMS

Sample Response

<AssignPrivateIpAddressesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>3fb591ba-558c-48f8-ae6b-c2f9d6d06425</requestId> <networkInterfaceId>eni-01d32da61c165ac3e</networkInterfaceId> <assignedPrivateIpAddressesSet> <item> <privateIpAddress>10.2.2.7</privateIpAddress> </item> <item> <privateIpAddress>10.2.2.5</privateIpAddress> </item> </assignedPrivateIpAddressesSet> <return>true</return> </AssignPrivateIpAddressesResponse>

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following:

隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。