> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gcore.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create and manage a subnetwork

export const MethodSection = ({children}) => children ?? null;

export const MethodSwitch = ({children}) => {
  const tabs = React.Children.toArray(children).map(c => {
    if (!c || !c.props) return null;
    if (c.props.id) return c;
    const inner = c.props.children;
    if (inner && inner.props && inner.props.id) return inner;
    return null;
  }).filter(Boolean);
  const firstId = tabs.length > 0 ? tabs[0].props.id : "";
  const [active, setActive] = React.useState(firstId);
  React.useEffect(() => {
    try {
      const saved = localStorage.getItem("gcore_docs_method");
      if (saved && tabs.find(t => t.props.id === saved)) {
        setActive(saved);
      }
    } catch (_) {}
  }, []);
  React.useEffect(() => {
    try {
      document.querySelectorAll("h2[id], h3[id]").forEach(heading => {
        const visible = heading.offsetParent !== null;
        document.querySelectorAll(`a[href="#${heading.id}"]`).forEach(link => {
          if (link.closest("h1,h2,h3,h4,h5,h6")) return;
          const li = link.closest("li");
          if (li) li.style.display = visible ? "" : "none";
        });
      });
    } catch (_) {}
    window.dispatchEvent(new Event("scroll"));
  }, [active]);
  const handleClick = id => {
    setActive(id);
    try {
      localStorage.setItem("gcore_docs_method", id);
    } catch (_) {}
  };
  return <div>
      <div className="not-prose flex gap-0 border-b border-zinc-200 dark:border-zinc-800 mb-8 mt-2" role="tablist">
        {tabs.map(tab => {
    const isActive = active === tab.props.id;
    return <button key={tab.props.id} role="tab" aria-selected={isActive} onClick={() => handleClick(tab.props.id)} className={["px-4 py-2 text-sm font-medium border-b-2 -mb-px transition-colors cursor-pointer", isActive ? "border-primary text-primary" : "border-transparent text-zinc-500 hover:text-zinc-800 dark:hover:text-zinc-200"].join(" ")}>
              {tab.props.label}
            </button>;
  })}
      </div>

      {tabs.map(tab => <div key={tab.props.id} style={{
    display: active === tab.props.id ? "" : "none"
  }}>
          {tab.props.children}
        </div>)}
    </div>;
};

<MethodSwitch>
  <MethodSection id="portal" label="Customer Portal">
    <p>A subnetwork is a range of IP addresses in a cloud network. Addresses from this range will be assigned to Virtual Machines in the cloud.</p>

    ## Create a subnetwork

    <p>A subnetwork can be created [during Virtual Machine creation](/cloud/virtual-instances/create-an-instance) or from the **Networks** page.</p>

    ### Step 1. Open the network

    1. In the [Gcore Customer Portal](https://portal.gcore.com), navigate to **Cloud** > **Networking**.

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/networks-page.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=152322e058ec9abf1fa226bd6cfdaae3" alt="Networks page open in the Customer Portal" width="966" height="380" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/networks-page.png" />
    </Frame>

    2. Find the network and click its name to open it.
    3. Click **Create subnet**. The **Create Subnet** dialog opens.

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/network-settings-create-subnet.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=035268687c1a68cd862cf78d74d1d085" alt="Network settings section with the highlighted Create subnet button" width="947" height="559" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/network-settings-create-subnet.png" />
    </Frame>

    ### Step 2. Set name and CIDR

    1. Enter the subnetwork name.
    2. Set a CIDR within one of the supported ranges:

    * 10.0.0.0/8
    * 172.16.0.0/12
    * 192.168.0.0/16
    * fc00::/7

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/create-subnetwork.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=d74476aab3d9dbf5efd4e8a66b3c9d19" alt="Create a subnetwork dialog" width="937" height="642" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/create-subnetwork.png" />
    </Frame>

    #### CIDR requirements

    * The CIDR must not overlap with other subnetworks in the same network — overlapping ranges cause network conflicts and break connectivity.
    * The CIDR cannot be changed after the subnetwork is created.
    * The prefix length must stay within the range of its base: /8–/32 for 10.0.0.0/8, /12–/32 for 172.16.0.0/12, and /16–/32 for 192.168.0.0/16.
    * Subnets with a /31 or /32 mask require the gateway to be disabled.

    ### Step 3. Configure DHCP and router

    1. (Optional) Select the **Enable DHCP** checkbox to assign IP addresses to machines in the subnet automatically.

    <Warning>
      For IPv6 networks, DHCP can only be enabled or disabled during subnetwork creation. Changing this setting later requires recreating the IPv6 subnetwork.
    </Warning>

    2. (Optional) Select the **Connect to network router** checkbox to automatically connect this subnet to the network router if one exists. This gives VMs internet access through the router and enables L3 routing between subnets connected to the same router. When selected, specify a custom **Gateway IP** address or leave it set to **Automatically** to assign one automatically.

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/create-subnetwork-name-cidr-dhcp.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=17b4371eb204e277e87c912f84cf89f5" alt="Network configuration example" width="935" height="644" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/create-subnetwork-name-cidr-dhcp.png" />
    </Frame>

    #### Gateway

    <p>The gateway IP must meet these requirements before saving the subnetwork configuration.</p>

    * The gateway IP must fall within the subnetwork's CIDR range. For 192.168.0.0/24, the valid range is 192.168.0.1–192.168.0.254. The network address (.0) and broadcast address (.255) are not valid.
    * Assigning a **Specific** gateway to more than one subnetwork in the same network causes routing conflicts — only one subnetwork should use a specific gateway IP.
    * When a Gcore Virtual Machine or Bare Metal server has both public and private interfaces, disable the default gateway on all private subnetworks — a conflict with the server's default gateway will prevent access.

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/disable-router-gateway.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=077a410e9c6a51b8de2d184aadd09e45" alt="Edit subnetwork dialog" width="933" height="629" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/disable-router-gateway.png" />
    </Frame>

    <Frame>
      <img src="https://mintcdn.com/gcore/gc7JxAc22A27n3nY/images/docs/cloud/networking/create-and-manage-a-subnetwork/gateway-ip-validation-error.png?fit=max&auto=format&n=gc7JxAc22A27n3nY&q=85&s=3b0887c455a46a9da77b5fcecd564d83" alt="Gateway IP validation error" width="929" height="649" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/gateway-ip-validation-error.png" />
    </Frame>

    <Warning>
      Changing the subnet gateway or disabling it may cause loss of connectivity between the private IP and the Floating IP (if they exist).
    </Warning>

    <p>When a private interface is added after creating a server, some operating systems may not activate it automatically — this is especially common for Bare Metal servers. In such cases, configure the interface manually.</p>

    #### Routing behavior

    * All subnets within the same network have L2 access to each other regardless of whether a router is present.
    * When subnets are connected to a router, L3 routing is available between those subnets, and VMs can reach external networks through the router's public interface.
    * Deselect **Connect to network router** to create an isolated subnet with no router connectivity.

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/enable-non-routable-subnetwork.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=cf43014f43802ace1b84456e73d3a49b" alt="Create subnetwork dialog showing non-routable option" width="938" height="647" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/enable-non-routable-subnetwork.png" />
    </Frame>

    ### Step 4. Configure DNS, host routes, and tags

    1. (Optional) Specify custom DNS servers for the subnetwork. If left blank, DNS servers are assigned automatically based on the subnet configuration.
    2. (Optional) Define host routes to control how traffic is distributed within the network:

    * **Destination:** Specify the network or host where the traffic is intended to go.
    * **Nexthop:** Choose the intermediate device — a router or gateway — through which traffic must pass to reach the destination.

    3. (Optional) Select **Add tags** to add metadata to the subnetwork.
    4. Click **Create subnet**.

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/create-subnetwork-custom-dns.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=9dbc5b3358e5bb6d08b88b8abaf8f8b8" alt="Custom DNS and host routes fields in the Create Subnetwork dialog" width="935" height="300" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/create-subnetwork-custom-dns.png" />
    </Frame>

    #### Host routes

    <p>Host routes direct traffic for specific destinations through a defined next-hop, overriding the default gateway for those prefixes. They are advertised to Virtual Machines via DHCP.</p>

    <p>Use host routes when VMs in a subnet need to reach a specific remote network through a router that is not the default gateway — for example, when connecting to a peered network or an on-premises segment.</p>

    | Field       | Format                                      | Example          |
    | ----------- | ------------------------------------------- | ---------------- |
    | Destination | CIDR notation                               | `10.10.0.0/24`   |
    | Nexthop     | IP address reachable from within the subnet | `192.168.10.254` |

    <p>Each subnetwork supports up to 20 host routes. If the next-hop IP is unreachable from the subnet, traffic to that destination will fail.</p>

    ## Manage subnetworks

    <p>Subnetworks are managed from the **Networking** page of the Customer Portal.</p>

    ### Rename a subnetwork

    1. In the Customer Portal, navigate to **Cloud** > **Networking**.

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/networks-page.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=152322e058ec9abf1fa226bd6cfdaae3" alt="Networks page open in the Customer Portal" width="966" height="380" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/networks-page.png" />
    </Frame>

    2. Find the network containing the subnetwork and click its name to open it.
    3. Click the three-dot icon next to the subnetwork, then click **Edit**.

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/rename-subnetwork.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=a91a0a8fd032cf8c463cd71442e8413f" alt="Network settings with the highlighted edit button" width="1088" height="538" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/rename-subnetwork.png" />
    </Frame>

    4. Update the subnetwork's name.
    5. Click **Save**.

    <p>The subnetwork has been renamed.</p>

    ### Delete a subnetwork

    <p>A subnetwork cannot be deleted if any of its IP addresses are in use — for example, if a Virtual Machine, load balancer, or other resource still has a port in that subnet.</p>

    1. In the Customer Portal, navigate to **Cloud** > **Networking**.
    2. Find the network containing the subnetwork and click its name to open it.
    3. Click the three-dot icon next to the subnetwork, then click **Delete**.
    4. Click **Delete** again to confirm.

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/confirm-subnetwork-deletion.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=2a96873d735b1396daffb65f4cb67762" alt="Delete subnetwork confirmation dialog" width="1710" height="812" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/confirm-subnetwork-deletion.png" />
    </Frame>

    <p>The subnetwork has been removed.</p>

    ## IPv4 and IPv6 reference

    <p>The following table compares IPv4 and IPv6 subnet features, including supported CIDR ranges, mask ranges, and connectivity options.</p>

    | Feature                 | IPv4                                                                                          | IPv6                                                                                                                 |
    | ----------------------- | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
    | CIDR ranges             | 10.0.0.0/8<br />172.16.0.0/12<br />192.168.0.0/16                                             | fc00::/7                                                                                                             |
    | Subnet mask range       | /8 - /32 for 10.0.0.0/8<br />/12 - /32 for 172.16.0.0/12<br />/16 - /32 for 192.168.0.0/16    | /7 - /126. Prefixes shorter than /64 (/63, /48, /7) are not recommended and may require manual system configuration. |
    | Floating IP support     | Yes                                                                                           | No                                                                                                                   |
    | Internet access         | Yes                                                                                           | No – private IPv6 subnets are not publicly routable<br />Yes – public IPv6                                           |
    | DHCP configuration      | Can be enabled or disabled                                                                    | Cannot be changed after creation                                                                                     |
    | Routing between subnets | L2 access: all subnets in the same network. L3 routing: subnets connected to the same router. | L2 access: all subnets in the same network. L3 routing: subnets connected to the same router.                        |
    | UI availability         | Available to all users                                                                        | Available to all users                                                                                               |
  </MethodSection>

  <MethodSection id="api" label="REST API">
    <p>Create a subnet inside an existing network and customize its DHCP and DNS settings to match the required connectivity configuration.</p>

    <Info>
      An [API token](/account-settings/api-tokens) is required, along with a [project ID](/api-reference/cloud/projects/list-projects) and [region ID](/api-reference/cloud/regions/list-regions).
    </Info>

    <p>Set these variables before running the examples:</p>

    ```bash theme={null}
    export GCORE_API_KEY="{YOUR_API_KEY}"
    export GCORE_CLOUD_PROJECT_ID="{YOUR_PROJECT_ID}"
    export GCORE_CLOUD_REGION_ID="{YOUR_REGION_ID}"
    export NETWORK_ID="{YOUR_NETWORK_ID}"
    ```

    <Info>
      **NETWORK\_ID** is the UUID of the [network](/cloud/networking/create-and-manage-a-network) in which to create the subnetwork.
    </Info>

    ## Quickstart

    <p>The following scripts create a subnet in an existing network, update its name and DNS servers, then delete it.</p>

    <Tabs>
      <Tab title="Python SDK">
        ```python theme={null}
        import os
        from gcore import Gcore

        client = Gcore()

        # Step 1. Create a subnet.
        task = client.cloud.networks.subnets.create(
            cidr="192.168.10.0/24",
            name="my-subnet",
            network_id=os.environ["NETWORK_ID"],
            enable_dhcp=True,
        )
        subnet_id = client.cloud.tasks.poll(task.tasks[0]).created_resources.subnets[0]
        print(f"Subnet ID: {subnet_id}")

        # Step 2. Get the subnet.
        subnet = client.cloud.networks.subnets.get(subnet_id)
        print(f"CIDR: {subnet.cidr}  gateway: {subnet.gateway_ip}")

        # Step 3. Update the subnet.
        subnet = client.cloud.networks.subnets.update(
            subnet_id,
            name="my-subnet-updated",
            dns_nameservers=["8.8.8.8", "1.1.1.1"],
        )
        print(f"Updated name: {subnet.name}")

        # Step 4. Delete the subnet.
        task = client.cloud.networks.subnets.delete(subnet_id)
        client.cloud.tasks.poll(task.tasks[0])
        print(f"Deleted subnet {subnet_id}")
        ```
      </Tab>

      <Tab title="Go SDK">
        ```go theme={null}
        package main

        import (
            "context"
            "fmt"
            "log"
            "os"

            gcore "github.com/G-Core/gcore-go"
            "github.com/G-Core/gcore-go/cloud"
            "github.com/G-Core/gcore-go/option"
        )

        func main() {
            client := gcore.NewClient()
            ctx := context.Background()

            // Step 1. Create a subnet.
            subnet, err := client.Cloud.NetworkSubnets.NewAndPoll(ctx, cloud.NetworkSubnetNewParams{
                Cidr:       "192.168.10.0/24",
                Name:       "my-subnet",
                NetworkID:  os.Getenv("NETWORK_ID"),
                EnableDhcp: gcore.Bool(true),
            })
            if err != nil {
                log.Fatalf("create subnet: %v", err)
            }
            fmt.Printf("Subnet ID: %s  CIDR: %s\n", subnet.ID, subnet.Cidr)

            // Step 2. Get the subnet.
            subnet, err = client.Cloud.NetworkSubnets.Get(ctx, subnet.ID, cloud.NetworkSubnetGetParams{})
            if err != nil {
                log.Fatalf("get subnet: %v", err)
            }
            fmt.Printf("CIDR: %s  gateway: %s\n", subnet.Cidr, subnet.GatewayIP)

            // Step 3. Update the subnet.
            subnet, err = client.Cloud.NetworkSubnets.Update(ctx, subnet.ID, cloud.NetworkSubnetUpdateParams{
                Name:           gcore.String("my-subnet-updated"),
                DNSNameservers: []string{"8.8.8.8", "1.1.1.1"},
            })
            if err != nil {
                log.Fatalf("update subnet: %v", err)
            }
            fmt.Printf("Updated name: %s\n", subnet.Name)

            // Step 4. Delete the subnet.
            if err = client.Cloud.NetworkSubnets.DeleteAndPoll(ctx, subnet.ID, cloud.NetworkSubnetDeleteParams{}); err != nil {
                log.Fatalf("delete subnet: %v", err)
            }
            fmt.Println("Subnet deleted.")
        }
        ```
      </Tab>
    </Tabs>

    ## Create a subnet

    <p>Provisions a new subnet inside an existing network. The backend assigns a gateway IP automatically unless one is specified.</p>

    | Parameter                   | Required | Description                                                                                                                                                                                                                                                                                                                      |
    | --------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | `cidr`                      | Yes      | IP range in CIDR notation, e.g. `192.168.10.0/24`. Must fall within `10.0.0.0/8`, `172.16.0.0/12`, or `192.168.0.0/16` for IPv4, or `fc00::/7` for IPv6. Must not overlap with other subnets in the same network.                                                                                                                |
    | `name`                      | Yes      | Name for the subnet.                                                                                                                                                                                                                                                                                                             |
    | `network_id`                | Yes      | ID of the network to attach this subnet to.                                                                                                                                                                                                                                                                                      |
    | `enable_dhcp`               | No       | Set to `true` to have DHCP assign IP addresses to VMs automatically. For IPv6 subnets this cannot be changed after creation.                                                                                                                                                                                                     |
    | `connect_to_network_router` | No       | Set to `false` to make the subnet non-routable (no internet access). Omit to use the network's default routing.                                                                                                                                                                                                                  |
    | `dns_nameservers`           | No       | DNS servers to advertise via DHCP. Omit or pass `null` to auto-assign defaults: DHCP-enabled subnets use the local DHCP server as resolver; subnets with DHCP disabled but a gateway receive `95.85.95.85` and `8.8.8.8`; subnets with DHCP disabled and no gateway receive no DNS servers. Pass `[]` to explicitly disable DNS. |

    <Tabs>
      <Tab title="Python SDK">
        ```python theme={null}
        import os
        from gcore import Gcore

        client = Gcore()

        task = client.cloud.networks.subnets.create(
            cidr="192.168.10.0/24",
            name="my-subnet",
            network_id=os.environ["NETWORK_ID"],
            enable_dhcp=True,
        )
        subnet_id = client.cloud.tasks.poll(task.tasks[0]).created_resources.subnets[0]
        print(f"Subnet ID: {subnet_id}")
        ```
      </Tab>

      <Tab title="Go SDK">
        ```go theme={null}
        subnet, err := client.Cloud.NetworkSubnets.NewAndPoll(ctx, cloud.NetworkSubnetNewParams{
            Cidr:       "192.168.10.0/24",
            Name:       "my-subnet",
            NetworkID:  os.Getenv("NETWORK_ID"),
            EnableDhcp: gcore.Bool(true),
        })
        if err != nil {
            log.Fatalf("create subnet: %v", err)
        }
        fmt.Printf("Subnet ID: %s\n", subnet.ID)
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl -X POST "https://api.gcore.com/cloud/v1/subnets/${GCORE_CLOUD_PROJECT_ID}/${GCORE_CLOUD_REGION_ID}" \
          -H "Authorization: APIKey ${GCORE_API_KEY}" \
          -H "Content-Type: application/json" \
          -d '{
            "cidr": "192.168.10.0/24",
            "name": "my-subnet",
            "network_id": "'${NETWORK_ID}'",
            "enable_dhcp": true
          }'
        ```

        Response:

        ```json theme={null}
        {
          "tasks": ["0e7e5e2c-a2b5-4a20-a118-face59aa1e27"]
        }
        ```

        Poll `GET /cloud/v1/tasks/{task_id}` every 5 seconds until `state` is `FINISHED`. The subnet ID is in `created_resources.subnets[0]`.

        ```json theme={null}
        {
          "state": "FINISHED",
          "created_resources": {
            "subnets": ["3f80fb47-4cda-43bd-95f9-18b316f7546e"]
          }
        }
        ```
      </Tab>
    </Tabs>

    ## Get subnet details

    <p>Retrieves the current configuration of the subnet, including the assigned gateway IP, DHCP status, and DNS servers.</p>

    <Tabs>
      <Tab title="Python SDK">
        ```python theme={null}
        subnet = client.cloud.networks.subnets.get(subnet_id)
        print(f"CIDR: {subnet.cidr}  gateway: {subnet.gateway_ip}")
        ```
      </Tab>

      <Tab title="Go SDK">
        ```go theme={null}
        subnet, err = client.Cloud.NetworkSubnets.Get(ctx, subnet.ID, cloud.NetworkSubnetGetParams{})
        if err != nil {
            log.Fatalf("get subnet: %v", err)
        }
        fmt.Printf("CIDR: %s  gateway: %s\n", subnet.Cidr, subnet.GatewayIP)
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl "https://api.gcore.com/cloud/v1/subnets/${GCORE_CLOUD_PROJECT_ID}/${GCORE_CLOUD_REGION_ID}/${SUBNET_ID}" \
          -H "Authorization: APIKey ${GCORE_API_KEY}"
        ```

        Response:

        ```json theme={null}
        {
          "id": "3f80fb47-4cda-43bd-95f9-18b316f7546e",
          "name": "my-subnet",
          "cidr": "192.168.10.0/24",
          "network_id": "6880a081-5f09-4437-9942-3eabee038666",
          "enable_dhcp": true,
          "ip_version": 4,
          "gateway_ip": "192.168.10.1",
          "dns_nameservers": [],
          "host_routes": []
        }
        ```
      </Tab>
    </Tabs>

    ## Update a subnet

    <p>Updates subnet settings in place. Only fields included in the request body are changed; the response returns the full updated subnet object.</p>

    | Parameter         | Description                                                                                                                 |
    | ----------------- | --------------------------------------------------------------------------------------------------------------------------- |
    | `name`            | New name for the subnet.                                                                                                    |
    | `enable_dhcp`     | Enable or disable DHCP. For IPv6 subnets this field is read-only after creation.                                            |
    | `dns_nameservers` | Replace the list of DNS server IPs. Pass `[]` to explicitly disable DNS. Pass `null` to reset to the auto-assigned default. |
    | `gateway_ip`      | Override the gateway IP. Set to `null` to remove the gateway advertisement from DHCP.                                       |

    <Tabs>
      <Tab title="Python SDK">
        ```python theme={null}
        subnet = client.cloud.networks.subnets.update(
            subnet_id,
            name="my-subnet-updated",
            dns_nameservers=["8.8.8.8", "1.1.1.1"],
        )
        print(f"Updated name: {subnet.name}")
        ```
      </Tab>

      <Tab title="Go SDK">
        ```go theme={null}
        subnet, err = client.Cloud.NetworkSubnets.Update(ctx, subnet.ID, cloud.NetworkSubnetUpdateParams{
            Name:           gcore.String("my-subnet-updated"),
            DNSNameservers: []string{"8.8.8.8", "1.1.1.1"},
        })
        if err != nil {
            log.Fatalf("update subnet: %v", err)
        }
        fmt.Printf("Updated name: %s\n", subnet.Name)
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl -X PATCH "https://api.gcore.com/cloud/v1/subnets/${GCORE_CLOUD_PROJECT_ID}/${GCORE_CLOUD_REGION_ID}/${SUBNET_ID}" \
          -H "Authorization: APIKey ${GCORE_API_KEY}" \
          -H "Content-Type: application/json" \
          -d '{
            "name": "my-subnet-updated",
            "dns_nameservers": ["8.8.8.8", "1.1.1.1"]
          }'
        ```

        Response:

        ```json theme={null}
        {
          "id": "3f80fb47-4cda-43bd-95f9-18b316f7546e",
          "name": "my-subnet-updated",
          "cidr": "192.168.10.0/24",
          "enable_dhcp": true,
          "dns_nameservers": ["8.8.8.8", "1.1.1.1"]
        }
        ```
      </Tab>
    </Tabs>

    ## Delete a subnet

    <p>Delete a subnet that has no active ports — deletion fails if any Virtual Machine, load balancer, or other resource still has a port in the subnet. The delete operation is asynchronous — poll the task until it reaches `FINISHED`.</p>

    <Tabs>
      <Tab title="Python SDK">
        ```python theme={null}
        task = client.cloud.networks.subnets.delete(subnet_id)
        client.cloud.tasks.poll(task.tasks[0])
        print(f"Deleted subnet {subnet_id}")
        ```
      </Tab>

      <Tab title="Go SDK">
        ```go theme={null}
        if err = client.Cloud.NetworkSubnets.DeleteAndPoll(ctx, subnet.ID, cloud.NetworkSubnetDeleteParams{}); err != nil {
            log.Fatalf("delete subnet: %v", err)
        }
        fmt.Println("Subnet deleted.")
        ```
      </Tab>

      <Tab title="curl">
        ```bash theme={null}
        curl -X DELETE "https://api.gcore.com/cloud/v1/subnets/${GCORE_CLOUD_PROJECT_ID}/${GCORE_CLOUD_REGION_ID}/${SUBNET_ID}" \
          -H "Authorization: APIKey ${GCORE_API_KEY}"
        ```

        Response:

        ```json theme={null}
        {
          "tasks": ["23096938-53a5-4d06-8f44-bcf7741e2414"]
        }
        ```
      </Tab>
    </Tabs>
  </MethodSection>

  <MethodSection id="terraform" label="Terraform">
    <p>Create a subnet inside an existing [network](/cloud/networking/create-and-manage-a-network) and configure its IP range, DHCP settings, and DNS servers. The [`gcore_cloud_network_subnet`](https://registry.terraform.io/providers/G-Core/gcore/latest/docs/resources/cloud_network_subnet) resource supports both IPv4 and IPv6.</p>

    <Info>
      Declare `var.network_id` with the ID of an existing [network](/cloud/networking/create-and-manage-a-network) before applying.
    </Info>

    ## Create a subnet

    <p>Defines a subnet with DHCP and optional custom DNS servers. The `cidr` must fall within `10.0.0.0/8`, `172.16.0.0/12`, or `192.168.0.0/16` for IPv4.</p>

    ```hcl theme={null}
    resource "gcore_cloud_network_subnet" "example" {
      project_id      = var.project_id
      region_id       = var.region_id
      name            = "my-subnet"
      cidr            = "192.168.10.0/24"
      network_id      = var.network_id
      enable_dhcp     = true
      dns_nameservers = ["8.8.8.8", "1.1.1.1"]  # optional
    }

    output "subnet_id" {
      value = gcore_cloud_network_subnet.example.id
    }
    ```

    ## Update a subnet

    <Warning>
      Modifying any field recreates the subnet — the existing subnet is deleted and a new one is created with a new ID. Virtual Machines attached to this subnet will briefly lose connectivity.
    </Warning>

    <p>Edit the field in the resource block and run `terraform apply`.</p>

    ```hcl theme={null}
    resource "gcore_cloud_network_subnet" "example" {
      project_id      = var.project_id
      region_id       = var.region_id
      name            = "my-subnet-updated"
      cidr            = "192.168.10.0/24"
      network_id      = var.network_id
      enable_dhcp     = true
      dns_nameservers = ["8.8.8.8", "8.8.4.4"]
    }
    ```

    ## Delete a subnet

    <p>Remove the resource block — Terraform deletes the subnet on the next `terraform apply`.</p>

    ```hcl theme={null}
    # Remove or comment out this block:
    # resource "gcore_cloud_network_subnet" "example" {
    #   project_id      = var.project_id
    #   region_id       = var.region_id
    #   name            = "my-subnet"
    #   cidr            = "192.168.10.0/24"
    #   network_id      = var.network_id
    #   enable_dhcp     = true
    #   dns_nameservers = ["8.8.8.8", "1.1.1.1"]
    # }
    ```

    ```bash theme={null}
    terraform apply
    ```

    ## Import a subnet

    <p>Use to bring a subnet created outside Terraform under configuration management.</p>

    ```hcl theme={null}
    resource "gcore_cloud_network_subnet" "existing" {
      project_id = var.project_id
      region_id  = var.region_id
      name       = "my-subnet"
      cidr       = "192.168.10.0/24"
      network_id = var.network_id
    }

    # terraform import gcore_cloud_network_subnet.existing '<project_id>/<region_id>/<subnet_id>'
    ```
  </MethodSection>
</MethodSwitch>
