All Products
Search
Document Center

Elastic Compute Service:AllocatePublicIpAddress

Last Updated:Aug 12, 2026

Assigns a public IP address to an ECS instance. We recommend that you call the ModifyInstanceNetworkSpec operation to assign a public IP address.

Operation description

Before you begin

  • Before you assign a public IP address, the instance must be in the Running (Running) or Stopped (Stopped) state.

  • If "LockReason" : "security" is included in the OperationLocks of an instance that is locked for security reasons, you cannot assign a public IP address to the instance.

  • Make sure that the public bandwidth of the instance is greater than 0 before you call this operation. You can call the ModifyInstanceNetworkSpec operation to adjust the bandwidth.

Precautions

  • Only users in the whitelist can specify the public IP address by using the IpAddress parameter. If the public bandwidth is greater than 0, you can set InstanceId to allocate a random public IP address. If the public bandwidth is 0, call the ModifyInstanceNetworkSpec operation to adjust the bandwidth before you call this operation to allocate a public IP address.

  • Only one public IP address can be allocated to an instance. If the instance already has a public IP address, the existing attached public IP address IpAddress is returned.

  • The new public IP address takes effect after you restart the instance (RebootInstance) or start the instance (StartInstance).

In addition to assigning a public IP address, you can associate an Elastic IP Address (EIP) with a VPC-connected ECS instance. For more information, see AssociateEipAddress.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ecs:AllocatePublicIpAddress

create

*Instance

acs:ecs:{#regionId}:{#accountId}:instance/{#instanceId}

None None

Request parameters

Parameter

Type

Required

Description

Example

InstanceId

string

Yes

The instance ID of the instance to which you want to allocate a public IP address.

Note

The public bandwidth of the instance must be greater than 0.

i-bp1gtjxuuvwj17zr****

IpAddress

string

No

The public IP address of the instance. If this parameter is left empty, the system randomly assigns an IP address.

Note

Only users in the whitelist can specify this parameter. Regular users cannot specify an IP address.

112.124.**.**

VlanId

string

No

The VLAN ID of the instance.

Note

This parameter will be deprecated. For better compatibility, use other parameters.

720

Response elements

Element

Type

Description

Example

object

IpAddress

string

The public IP address of the instance.

112.124.**.**

RequestId

string

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

Examples

Success response

JSON format

{
  "IpAddress": "112.124.**.**",
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidOperation.AllocateFailed The current instance failed to allocate public IP, please try again later.
400 InvalidIpAddress.Malformed The specified parameter "IpAddress" is not valid.
400 OperationDenied Specified operation is denied as your instance is in VPC. The operation is not supported while the instance resides in a VPC.
400 InsufficientPublicIp Ip address not found.
400 AllocateIpInvalidInstanceBandwidth OperationDenied The InternetMaxBandwidthOut of the specified instance cannot be less than 0. The operation is not supported while the maximum outbound public bandwidth is not greater than 0 Mbit/s.
400 OperationDenied.CloudboxNotSupport This operation is denied, because the specified ECS instance which is in the Cloudbox dose not support PublicIp or Eip.
400 OperationDenied.DedicatedRegionNotSupported This operation is denied, because the specified ECS instance which is in the dedicated region dose not support PublicIp or Eip. error of api not supported by the exclusive cloud
500 InternalError The request processing has failed due to some unknown error.
500 InvalidOperation.AllocateIpFailed Failed to allocate the specific IP, please ensure the IP is available. Failed to assign specific IP, please make sure the IP is available.
403 IncorrectInstanceStatus The current status of the resource does not support this operation.
403 InstanceLockedForSecurity The specified operation is denied as your instance is locked for security reasons. The instance is locked for security reasons. Contact security technical support for assistance.
403 InstanceExpiredOrInArrears The specified operation is denied as your prepay instance is expired (prepay mode) or in arrears (afterpay mode).
403 IpInUse The specified IP is already in use. The specified IP address is already in use on another instance.
403 AllocatedAlready There is an IpAddress allocated already for the specified instance. The instance to which you attempt to assign an IP address is already assigned another IP address.
403 AllocateIp.Fail The specified instance fails to allocate ip, please try again.
403 NAT_PUBLIC_IP_BINDING_FAILED Binding nat public ip failed.
403 NAT_PUBLIC_IP_ALLOCATE_FAILED Nat public ip binding failed. The public IP address cannot be associated.
403 InvalidIpAddress.NotPublic The specified IP is not public address.
404 InvalidInstanceId.NotFound The specified InstanceId does not exist. The specified instanceId is invalid.
404 InvalidVlanId.NotFound The VlanId provided does not exist in our records. The specified VLAN ID does not exist.
404 InvalidIpAddress.NotFound The specified IP is not in the specified vlan. The specified IP address is not in the specified VLAN.
409 OperationConflict Request was denied due to conflict with a previous request,please try again later. The requested resource conflicts with a previous request.
409 TokenProcessing The previous token request is still processing. Please try again later.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.