> For the complete documentation index, see [llms.txt](https://docs.console.zenlayer.com/api-reference/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.console.zenlayer.com/api-reference/zec/vpc-network/modifysubnetstacktype.md).

# ModifySubnetStackType

## 1. API Description

This API (ModifySubnetStackType) is used to modify the IP stack type of a subnet (IPv4 / IPv4\_IPv6 / IPv6). When changing to dual stack or IPv6 only, the IPv6 type and the corresponding CIDR block must be configured.

{% hint style="info" %}
**Notes**

* Switching from `IPv4` to `IPv4_IPv6` is supported: after the switch, an IPv6 CIDR block is obtained.
* Switching from `IPv4_IPv6` to `IPv4` (disabling IPv6) is supported: both public and private IPv6 subnets are supported. Before disabling it, make sure that no IPv6 address in the subnet is in use — the IPv6 addresses of network interfaces are deleted through [UnassignNetworkInterfaceIpv6](/api-reference/zec/public-ipv6/unassignnetworkinterfaceipv6.md), and the IPv6 VIPs of load balancers are deleted through [DeleteIpv6Addresses](/api-reference/zec/public-ipv6/deleteipv6addresses.md).
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name  | Required | Type                                                                   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| --------------- | -------- | ---------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| subnetId        | Yes      | String                                                                 | <p>ID of the subnet to be operated on.</p><p>It can be obtained by calling <a href="/api-reference/zec/vpc-network/describesubnets.md">DescribeSubnets</a>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| stackType       | Yes      | [SubnetStackType](/api-reference/zec/datastructure.md#subnetstacktype) | <p>Subnet stack type.</p><p><code>IPv4\_IPv6</code>: public IPv6 is enabled; whether it is public or private is specified by <code>ipv6Type</code>.</p><p><code>IPv4</code>: IPv6 is disabled. Before disabling it, make sure that no IPv6 address in the subnet is in use: the IPv6 addresses of network interfaces are deleted through <a href="/api-reference/zec/public-ipv6/unassignnetworkinterfaceipv6.md">UnassignNetworkInterfaceIpv6</a>, and the IPv6 VIPs of load balancers are deleted through <a href="/api-reference/zec/public-ipv6/deleteipv6addresses.md">DeleteIpv6Addresses</a>.</p> |
| ipv6Type        | No       | [IPv6Type](/api-reference/zec/datastructure.md#ipv6type)               | <p>Type of the IPv6 address.</p><p>Required when <code>stackType</code> is <code>IPv4\_IPv6</code>.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ipv6CidrBlockId | No       | String                                                                 | <p>ID of the public IPv6 CIDR block.</p><p>This field can only be specified when <code>ipv6Type</code> is <code>Public</code>.</p><p>If not specified, it will be allocated from the system's default IP pool.</p>                                                                                                                                                                                                                                                                                                                                                                                       |
| ipv6MaskLength  | No       | Integer                                                                | <p>The size of the IPv6 CIDR prefix assigned to the instance.</p><p>This parameter must be used together with the <code>ipv6CidrBlockId</code> parameter.</p><p>The default value is 96 if not explicitly provided.</p><p>The minimum value must be greater than or equal to the prefix of the specified <code>ipv6CidrBlockId</code>, and the maximum value cannot exceed 96.</p><p>Value range: \[-, 96]</p>                                                                                                                                                                                           |

## 3. Output Parameters

| Parameter Name | Type   | Description                                                                                                           |
| -------------- | ------ | --------------------------------------------------------------------------------------------------------------------- |
| requestId      | String | <p>The unique request ID, which is returned for each request.</p><p>RequestId is required for locating a problem.</p> |
| ipv6CidrBlock  | String | IPv6 CIDR block of subnet.                                                                                            |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**1. Modify the subnet stack type: IPv4 → IPv4\_IPv6, specifying private IPv6.**

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: ModifySubnetStackType
<Common Request Params>

Request：
{
  "subnetId": "XXX",
  "stackType": "IPv4_IPv6",
  "ipv6Type": "Private"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "ipv6CidrBlock": "f0xxxx:xx:xxx::/64"
  }
}
```

**2. Disable public IPv6 for the subnet: IPv4\_IPv6 → IPv4.**

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: ModifySubnetStackType
<Common Request Params>

Request：
{
  "subnetId": "XXX",
  "stackType": "IPv4"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3"
  }
}
```

{% endtab %}
{% endtabs %}

## 5. Developer Resources

Zenlayer Cloud API 2.0 integrates [SDKs](/api-reference/api-introduction/toolkit/api-sdk.md)，to make it easier for you to call APIs. More programming languages will be supported.

## 6. Error Codes

The following only lists the error codes related to the API business logic. For other error codes, see [Common Error Codes](/api-reference/api-introduction/instruction/commonerrorcode.md).

| HTTP Status Code | Error Code                                         | Description                                                                                                                                                                    |
| ---------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 400              | INVALID\_CIDR\_BLOCK\_STATUS                       | The CIDR block state is invalid.                                                                                                                                               |
| 404              | INVALID\_CIDR\_IPV6\_NOT\_FOUND                    | The IPv6 CIDR block does not exist.                                                                                                                                            |
| 400              | INVALID\_CIDR\_REGION\_MISMATCH                    | The subnet region does not match the IPv6 CIDR block region.                                                                                                                   |
| 400              | INVALID\_MASK\_LENGTH                              | The IPv6 address mask length must be greater than or equal to the subnet IPv6 prefix length.                                                                                   |
| 400              | INVALID\_SUBNET\_HAS\_IPV6\_ALLOCATED              | The subnet still has vNICs or load balancers holding IPv6 addresses. Call UnassignNetworkInterfaceIpv6 for the vNICs and DeleteIpv6Addresses for the load balancer VIPs first. |
| 404              | INVALID\_SUBNET\_NOT\_FOUND                        | Subnet does not exist.                                                                                                                                                         |
| 404              | INVALID\_VPC\_NOT\_FOUND                           | The global VPC does not exist.                                                                                                                                                 |
| 404              | INVALID\_ZONE\_NOT\_FOUND                          | Region does not exist.                                                                                                                                                         |
| 400              | OPERATION\_DENIED\_NO\_AVAILABLE\_CIDR             | No available CIDR block.                                                                                                                                                       |
| 400              | OPERATION\_DENIED\_REGION\_NOT\_SUPPORT\_PUB\_IPV6 | Public IPv6 is not supported in the specified region.                                                                                                                          |
| 400              | OPERATION\_DENIED\_SUBNET\_TYPE\_NOT\_SUPPORT      | Operations on subnets with such IP stack type is not supported.                                                                                                                |
| 400              | OPERATION\_DENIED\_VPC\_NOT\_SUPPORT\_PRI\_IPV6    | Private IPv6 is not supported for the specified global VPC.                                                                                                                    |
