Help Center/ Elastic Cloud Server/ API Reference/ APIs (Recommended)/ NIC Management/ Updating Attributes of a Specified NIC for an ECS
Updated on 2024-06-03 GMT+08:00

Updating Attributes of a Specified NIC for an ECS

Function

This API is used to update the attributes of a specified NIC for an ECS. Currently, only the NIC IP address can be updated.

Constraints

  • The attributes of a specified NIC can be updated only for stopped ECSs.
  • Only the attributes of the primary NIC of ECSs can be updated.
  • If only the IPv4 protocol is enabled for a NIC, its IPv6 address cannot be modified.
  • If only the IPv4 protocol is enabled for a NIC, its IPv4 address cannot be modified across VPCs.
  • If the IPv6 protocol is enabled for a NIC, its IPv4 and IPv6 addresses cannot be modified across subnets.
  • If the IPv6 protocol is enabled for a NIC and a shared bandwidth or virtual IP address is bound to the NIC, its IPv4 and IPv6 addresses cannot be modified.

URI

POST /v1/{project_id}/cloudservers/{server_id}/os-interface/{port_id}/change-network-interface

Table 1 describes the parameters in the URI.

Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

Specifies the project ID.

For details about how to obtain the ID, see Obtaining a Project ID.

server_id

Yes

Specifies the ECS ID.

port_id

Yes

Specifies the NIC ID.

Request

Table 2 describes the request parameters.

Table 2 Request parameters

Parameter

Mandatory

Type

Description

subnet_id

No

String

Specifies the subnet ID in UUID format. This parameter must be specified when the IPv4 address is updated. It can be left blank when the IPv6 address is updated.

ip_address

No

String

Specifies the IPv4 address. If this parameter is an empty string, a random IPv4 address of a NIC is updated.

Note:

  • Either ip_address or ipv6_address must be specified.
  • ip_address and ipv6_address cannot be specified at the same time.

ipv6_address

No

String

Specifies the IPv6 address. If this parameter is an empty string, a random IPv6 address of a NIC is updated.

Note:

  • Either ipv6_address or ip_address must be specified.
  • ipv6_address and ip_address cannot be specified at the same time.

Response

Table 3 describes the response parameters.

Table 3 Response parameters

Parameter

Type

Description

id

String

Specifies the NIC ID.

subnet_id

String

Specifies the subnet ID.

ip_address

String

Specifies the IPv4 address of a NIC.

ipv6_address

String

Specifies the IPv6 address of a NIC. This parameter is not returned for NICs without the IPv6 protocol enabled.

Example Request

  • Update the NIC and specify an IPv4 address for an ECS.
    POST  https://{endpoint}/v1/{project_id}/cloudservers/{server_id}/os-interface/{port_id}/change-network-interface
    
    {
        "subnet_id": "7bf939cc-167f-49d5-a933-9cca504210ab",
        "ip_address":"192.168.1.159"
    }
  • Update the NIC for an ECS and randomly assign an IPv4 address to it.
    POST  https://{endpoint}/v1/{project_id}/cloudservers/{server_id}/os-interface/{port_id}/change-network-interface
    
    {
        "subnet_id": "7bf939cc-167f-49d5-a933-9cca504210ab",
        "ip_address":""
    }
  • Update the NIC and specify an IPv6 address for an ECS.
    POST  https://{endpoint}/v1/{project_id}/cloudservers/{server_id}/os-interface/{port_id}/change-network-interface
    
    {
        "subnet_id": "7bf939cc-167f-49d5-a933-9cca504210ab",
        "ipv6_address":"2001:db8:a583:578:2840:2d9f:27d4:2713"
    }
  • Update the NIC for an ECS and randomly assign an IPv6 address to it.
    POST  https://{endpoint}/v1/{project_id}/cloudservers/{server_id}/os-interface/{port_id}/change-network-interface
    
    {
        "subnet_id": "7bf939cc-167f-49d5-a933-9cca504210ab",
        "ipv6_address":""
    }

Example Response

{
    "id": "6bcb3ac6-c5f7-45a8-b6df-aadc6839c2d9",
    "subnet_id": "7bf939cc-167f-49d5-a933-9cca504210ab",
    "ip_address": "192.168.1.159",
    "ipv6_address": "2001:db8:a583:578:192:168:1:159"
}

Error Codes

See Error Codes.