> ## Documentation Index
> Fetch the complete documentation index at: https://gcore.com/docs/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">
    A subnetwork is a range of IP addresses in a cloud network. Addresses from this range will be assigned to Virtual Machines (VMs) in the cloud.

    ## Create a subnetwork

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

    ### Create a subnetwork from the networks page

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

    <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>

    <p>2. Find the network and click its name to open it.</p>
    <p>3. Click **Create subnet**.</p>

    <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>

    <p>4. A new **Create Subnet** dialog will open.</p>
    5\. Enter the subnetwork name.
    6\. Set a CIDR within the specified range:

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

    See [IP range](#ip-range) for valid mask ranges per CIDR prefix. The CIDR cannot be changed after the subnetwork is created.

    <p>7. (optional) Turn on the **Enable DHCP** toggle to assign IP addresses to machines in the subnet automatically.</p>

    <Warning>
      **Warning**

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

    <p>8. (optional) Enable the **Connect to network router** toggle 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 enabled, specify a custom **Gateway IP** address or leave it set to **Automatically** to assign one automatically.</p>

    <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>

    <p>9. (optional) Specify custom DNS servers for the subnetwork. If left blank, DNS servers are assigned automatically based on your subnet configuration.</p>

    10. Define how traffic is distributed within the network. Each subnetwork supports up to 20 host routes.

    * **Destination:** Specify the network or host where the traffic is intended to go.
    * **Next hop:** Choose the intermediate device (e.g., a router or gateway) through which traffic must pass to reach the destination.

    11. (optional) Turn on **Add tags** to add metadata to the subnetwork.
        <p>12. Click **Create subnet**.</p>

    <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

    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.

    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.

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

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

    ### IP range

    <p>The address range is specified in CIDR format when creating a subnetwork.</p>

    <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>

    <p>The subnetwork's IP range must not overlap with others in the same network — overlapping subnets cause network conflicts and break connectivity.</p>

    Virtual machines in the same network communicate using private IP addresses, but subnetworks in different networks cannot communicate unless routing is configured.

    The subnetwork size is set using the classless addressing (CIDR) method, and both private IPv6 and IPv4 addresses are supported.

    Acceptable CIDR ranges for IPv4 addresses:

    * 10.0.0.0 - 10.255.255.255
    * 172.16.0.0 - 172.31.255.255
    * 192.168.0.0 - 192.168.255.255

    The minimum mask length equals the CIDR prefix: /8 for 10.0.0.0/8, /12 for 172.16.0.0/12, and /16 for 192.168.0.0/16. Subnets with a /31 or /32 mask require the gateway to be disabled.

    ### Comparison of IPv4 and IPv6 subnets

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

    | 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 (e.g. /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                                                                                                    |

    ### Network routing

    All subnets within the same network have L2 access to each other regardless of whether a router is present. When a router exists and subnets are connected to it, L3 routing is available between those subnets, and VMs can reach external networks through the router's public interface.

    <p>When the **Connect to network router** toggle is enabled, the subnet is automatically connected to the network router (if one exists), giving VMs internet access and enabling L3 routing between subnets on the same router. Disable this toggle to create an isolated subnet with no router connectivity.</p>

    <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" width="938" height="647" data-path="images/docs/cloud/networking/create-and-manage-a-subnetwork/enable-non-routable-subnetwork.png" />
    </Frame>

    ### Default gateway

    The default gateway controls how traffic leaves a subnetwork. We recommend leaving the **Gateway IP** set to **Automatically** unless you have a specific reason to override it. Misconfiguring it can cause connectivity loss, so review the following guidelines before making changes.

    <Warning>
      **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>

    When a Gcore Virtual Machine or Bare Metal server has both public and private interfaces, disable the default gateway for all private subnetworks — a conflict with the server's default gateway will prevent access.

    <p>When configuring a gateway in a private subnetwork, verify that only one subnetwork is routable by checking that only one subnetwork has the **Gateway IP** set to **Specific**.</p>

    <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>

    <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>

    **Gateway IP validation**

    <p>Gateway IP validation prevents misconfiguration during creation or updates. The gateway IP must fall within the subnetwork's CIDR range — for a typical /24 subnet such as 192.168.0.0/24, the gateway IP must be between 192.168.0.1 and 192.168.0.254 — the network address (.0) and broadcast address (.255) are not valid gateway values.</p>

    <Frame>
      <img src="https://mintcdn.com/gcore/84ejI3CefETiNdFt/images/docs/cloud/networking/create-and-manage-a-subnetwork/gateway_ip_validation_error.png?fit=max&auto=format&n=84ejI3CefETiNdFt&q=85&s=83a7e0539df22d27f6dc9a24e47412d4" 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>

    ## Manage subnetworks

    Subnetworks are managed from the **Networking** page of the Customer Portal.

    ### Rename a subnetwork

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

    <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>

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

    <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>

    <p>4. Update the subnetwork's name.</p>
    5\. Click **Save**.

    The subnetwork has been renamed.

    ### Delete a subnetwork

    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**.</p>

    <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>

    <p>2. Find the network containing the subnetwork and click its name to open it.</p>
    3\. Click the three-dot icon next to the subnetwork, then click **Delete**.
    <p>4. Click **Delete** again to confirm.</p>

    <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 successfully removed.</p>
  </MethodSection>

  <MethodSection id="api" label="REST API">
    Create a subnet inside an existing network and customize its DHCP and DNS settings to match your connectivity requirements.

    <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>

    Set these variables before running the examples:

    ```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"
        )

        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>

    ## Clean up

    <p>Delete a subnet that is not attached to any Virtual Machine. 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>
