> 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/compute/zec/vpc-network/modifysubnetstacktype.md).

# ModifySubnetStackType

## 1. API Description

This API (ModifySubnetStackType) is used to modify the IP stack type of the specified subnet (IPv4, IPv4\_IPv6, or IPv6). When switching to dual-stack or IPv6-only, you must provide the IPv6 type and the corresponding CIDR block configuration.

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

* Switching `IPv4` to `IPv4_IPv6` (enabling IPv6): you must specify `ipv6Type` (public `Public` / private `Private`); after the change, an IPv6 address block is assigned to the subnet.
* Switching `IPv4_IPv6` to `IPv4` (disabling IPv6): supported for both public and private IPv6 subnets; before proceeding, all NICs in the subnet must have their IPv6 addresses removed via `UnassignNetworkInterfaceIpv6`.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name  | Required | Type                                                                           | Description                                                                                                                                                                                                                                                                                                                                                                                                    |
| --------------- | -------- | ------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| subnetId        | Yes      | String                                                                         | Subnet ID.                                                                                                                                                                                                                                                                                                                                                                                                     |
| stackType       | Yes      | [SubnetStackType](/api-reference/compute/zec/datastructure.md#subnetstacktype) | <p>IP stack type of the subnet.</p><p><code>IPv4\_IPv6</code>: enable IPv6 — public or private is determined by <code>ipv6Type</code>.</p><p><code>IPv4</code>: disable IPv6 — supported for both public and private IPv6 subnets; before proceeding, all NICs in the subnet must have their IPv6 addresses removed via <code>UnassignNetworkInterfaceIpv6</code>.</p>                                         |
| ipv6Type        | No       | [IPv6Type](/api-reference/compute/zec/datastructure.md#ipv6type)               | <p>IPv6 type. Required when <code>stackType</code> is <code>IPv4\_IPv6</code>.</p><p><code>Public</code>: public IPv6; <code>Private</code>: private IPv6.</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. Switch the subnet stack type from IPv4 to IPv4\_IPv6 with 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": "<subnetId>",
  "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 subnet IPv6: 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": "<subnetId>",
  "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                    | 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 network interfaces with IPv6 allocated. Please call UnassignNetworkInterfaceIpv6 on all of them 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.                                                                 |
