帮助文档 Logo
平台使用
阿里云
百度云
移动云
智算服务
教育生态
登录 →
帮助文档 Logo
平台使用 阿里云 百度云 移动云 智算服务 教育生态
登录
  1. 首页
  2. 阿里云
  3. 云服务器 ECS
  4. 开发参考
  5. API参考(ECS)
  6. API目录
  7. 网络
  8. AllocatePublicIpAddress - 分配公网IP

AllocatePublicIpAddress - 分配公网IP

  • 网络
  • 发布于 2025-04-01
  • 0 次阅读
文档编辑
文档编辑

为一台ECS实例分配一个公网IP地址。

接口说明

使用须知

  • 分配公网 IP 地址之前,实例必须处于运行中(Running)或者已停止(Stopped)状态。

  • 被安全控制的实例的OperationLocks中标记了"LockReason" : "security"时,不能分配公网 IP 地址。

  • 调用该接口时请确保实例带宽大于 0,您可以调用 ModifyInstanceNetworkSpec 接口调整带宽。

注意事项

  • 仅白名单用户支持指定公网 IP 参数IpAddress,若公网带宽大于 0,您可以设置InstanceId进行随机分配;若公网带宽为 0,您需要调用 ModifyInstanceNetworkSpec 调整带宽之后再通过该接口分配。

  • 一台实例只能分配一个公网 IP 地址。如果实例已经拥有一个公网 IP 地址,将返回已绑定的公网 IP 地址IpAddress。

  • 重启实例( RebootInstance )或者启动实例( StartInstance )后,新的公网 IP 地址生效。

除分配公网 IP 之外,您还可以给 VPC 类型 ECS 实例绑定弹性公网 IP(EIP)。更多信息,请参见 AssociateEipAddress 。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

调试

授权信息

下表是API对应的授权信息,可以在RAM权限策略语句的Action元素中使用,用来给RAM用户或RAM角色授予调用此API的权限。具体说明如下:

  • 操作:是指具体的权限点。
  • 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。
  • 资源类型:是指操作中支持授权的资源类型。具体说明如下:
    • 对于必选的资源类型,用前面加 * 表示。
    • 对于不支持资源级授权的操作,用全部资源表示。
  • 条件关键字:是指云产品自身定义的条件关键字。
  • 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。
操作访问级别资源类型条件关键字关联操作
ecs:AllocatePublicIpAddresscreate
*Instance
acs:ecs:{#regionId}:{#accountId}:instance/{#instanceId}
    无
无

请求参数

名称类型必填描述示例值
InstanceIdstring是

待分配 IP 地址的实例 ID。

说明 该实例带宽必须大于 0。
i-bp1gtjxuuvwj17zr****
IpAddressstring否

实例的公网 IP 地址。如果该参数值为空,则默认由系统随机分配 IP 地址。

说明 该参数只支持白名单用户指定,普通用户不支持指定 IP 地址。
112.124.**.**
VlanIdstring否

实例的 VLAN ID。

说明 该参数即将被弃用,为提高兼容性,请尽量使用其他参数。
720

返回参数

名称类型描述示例值
object
IpAddressstring

实例的公网 IP 地址。

112.124.**.**
RequestIdstring

请求 ID。

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

示例

正常返回示例

JSON格式

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

错误码

HTTP status code错误码错误信息描述
400InvalidOperation.AllocateFailedThe current instance failed to allocate public IP, please try again later.-
400InvalidIpAddress.MalformedThe specified parameter "IpAddress" is not valid.-
400OperationDeniedSpecified operation is denied as your instance is in VPC.由于实例存在于 VPC 中,指定的操作不合法。
400InsufficientPublicIpIp address not found.-
400AllocateIpInvalidInstanceBandwidthOperationDenied The InternetMaxBandwidthOut of the specified instance cannot be less than 0.当前操作无效,请保证最大输出带宽大于0。
400OperationDeniedThe specified parameter "VlanId" is not valid or vlan has not enough IP address.-
400OperationDeniedThe specified instance already has a public IP.-
400OperationDenied.CloudboxNotSupportThis operation is denied, because the specified ECS instance which is in the Cloudbox dose not support PublicIp or Eip.-
400OperationDenied.DedicatedRegionNotSupportedThis operation is denied, because the specified ECS instance which is in the dedicated region dose not support PublicIp or Eip.专属云不支持的api的报错
403IncorrectInstanceStatusThe current status of the resource does not support this operation.该资源目前的状态不支持此操作。
403InstanceLockedForSecurityThe specified operation is denied as your instance is locked for security reasons.实例被安全锁定。
403InstanceExpiredOrInArrearsThe specified operation is denied as your prepay instance is expired (prepay mode) or in arrears (afterpay mode).实例已过期或者欠费,请您续费或者结清后再进行操作。
403IpInUseThe specified IP is already in use.使用指定IP进行绑定时,IP已经被使用在别的机器上。
403AllocatedAlreadyThere is an IpAddress allocated already for the specified instance.使用指定 IP 进行绑定时,该实例已经被分配了别的 IP 地址。
403AllocateIp.FailThe specified instance fails to allocate ip, please try again.-
403NAT_PUBLIC_IP_BINDING_FAILEDBinding nat public ip failed.-
403NAT_PUBLIC_IP_ALLOCATE_FAILEDNat public ip binding failed.公网 IP 绑定失败。
403InvalidIpAddress.NotPublicThe specified IP is not public address.-
403AllocatedAlreadyAn IpAddress has been assigned to the specified instance.-
404InvalidInstanceId.NotFoundThe specified InstanceId does not exist.指定的InstanceId不存在。
404InvalidVlanId.NotFoundThe VlanId provided does not exist in our records.指定的虚拟局域网 ID 不存在。
404InvalidIpAddress.NotFoundThe specified IP is not in the specified vlan.指定的 IP 不在指定的虚拟局域网内。
500InternalErrorThe request processing has failed due to some unknown error.内部错误,请重试。

访问错误中心查看更多错误码。

变更历史

变更时间变更内容概要操作
2024-12-20OpenAPI 描述信息更新、OpenAPI 错误码发生变更查看变更详情
2023-10-10OpenAPI 错误码发生变更查看变更详情
相关文章

AllocatePublicIpAddress - 分配公网IP 2025-04-01 11:58

为一台ECS实例分配一个公网IP地址。 接口说明

AttachClassicLinkVpc - 将经典网络类型实例连接到专有网络VPC 2025-04-01 11:58

调用AttachClassicLinkVpc将一台经典网络类型实例连接到专有网络VPC中,使经典网络类型实例可以和VPC中的云资源私网互通。

ConvertNatPublicIpToEip - 将公网IP地址转化为弹性公网IP 2025-04-01 11:58

将一台专有网络VPC类型ECS实例的公网IP地址(PublicIP)转化为弹性公网IP(EIP)。

DescribeBandwidthLimitation - 查询不同实例规格公网带宽上限 2025-04-01 11:58

调用DescribeBandwidthLimitation查询不同实例规格可以购买、升级或降配的公网带宽上限。

DescribeClassicLinkInstances - 查询建立了连接的经典网络类型实例 2025-04-01 11:58

查询一台或多台与专有网络VPC建立了连接的经典网络类型实例。 接口说明

DetachClassicLinkVpc - 取消经典网络类型实例与VPC的连接 2025-04-01 11:58

调用DetachClassicLinkVpc取消一台经典网络类型ECS实例与专有网络VPC的连接(ClassicLink)。取消ClassicLink后,经典网络类型实例无法与VPC内的实例互通。

目录
Copyright © 2025 your company All Rights Reserved. Powered by 博智数字服务平台.
闽ICP备08105208号-1