Create Subnet
POST /v2.0/subnets
Create a subnet in a network.
OpenStack Networking does not try to derive the correct IP version from the CIDR. If you do not specify the gateway_ip attribute, OpenStack Networking allocates an address from the CIDR for the gateway for the subnet.
To specify a subnet without a gateway, set the gateway_ip attribute to null in the request body. If you do not specify the allocation_pools attribute, OpenStack Networking automatically allocates pools for covering all IP addresses in the CIDR, excluding the address reserved for the subnet gateway. When you specify both the allocation_pools and gateway_ip attributes, ensure that the gateway IP does not overlap with the allocation pools; otherwise, the call returns 409 Conflict.
A subnet can have one or more name servers and host routes. Hosts in this subnet use the name servers. Devices with IP addresses from this subnet, not including the local subnet route, use the host routes.
Specify the ipv6_ra_mode and ipv6_address_mode attributes to create subnets that support IPv6 configurations, such as SLAAC, DHCPv6 stateful, and DHCPv6 stateless configurations.
Optionally, a subnet can be associated with a network segment when it is created by specifying the segment_id of a valid segment on the specified network (routed networks).
Source: create-subnet
Request
Body parameters
| Name | In | Type | Description |
|---|---|---|---|
subnet | body | object | A subnet object. |
tenant_id (Optional) | body | string | The ID of the project that owns the resource. Admin/advsvc can specify a different project. |
project_id (Optional) | body | string | The ID of the project that owns the resource. Admin/advsvc can specify a different project. |
name (Optional) | body | string | Human-readable name of the subnet. |
description (Optional) | body | string | Human-readable description. |
enable_dhcp (Optional) | body | boolean | Whether DHCP is enabled for the subnet. Default: true. |
network_id | body | string | The ID of the network to which the subnet belongs. |
dns_nameservers (Optional) | body | array | List of DNS name servers associated with the subnet. |
allocation_pools (Optional) | body | array | Allocation pools with start and end IP addresses for this subnet. If omitted, pools are auto-allocated (excluding gateway). |
host_routes (Optional) | body | array | Additional routes. Each item has destination and nexthop. |
ip_version | body | integer | IP protocol version. 4 or 6. |
gateway_ip (Optional) | body | string | Gateway IP of this subnet. Use null to create without a gateway. If omitted, an address is allocated from the CIDR. |
cidr | body | string | The CIDR of the subnet. |
prefixlen (Optional) | body | integer | Prefix length to use for allocation from a subnet pool. |
ipv6_address_mode (Optional) | body | string | IPv6 address assignment mode: slaac, dhcpv6-stateful, dhcpv6-stateless. |
ipv6_ra_mode (Optional) | body | string | IPv6 router advertisement mode: slaac, dhcpv6-stateful, dhcpv6-stateless. |
segment_id (Optional) | body | string | The ID of a network segment the subnet is associated with. |
subnetpool_id (Optional) | body | string | The ID of the subnet pool associated with the subnet. |
use_default_subnetpool (Optional) | body | boolean | Whether to allocate this subnet from the default subnet pool. |
service_types (Optional) | body | array | Service types associated with the subnet. |
dns_publish_fixed_ip (Optional) | body | boolean | Whether to publish DNS records for IPs from this subnet. Default: false. |
Example requests
Using curl (create a subnet on a private network)
curl -ks -H 'Content-Type: application/json' \
-H 'X-Auth-Token: gAAAAA<...>' -d '
{
"subnet": {
"enable_dhcp": true,
"network_id": "170546a1-a70a-40af-93e2-9261c7c05b77",
"dns_nameservers": [
"10.30.0.27",
"10.30.0.28"
],
"allocation_pools": [
{
"start": "192.168.10.2",
"end": "192.168.10.254"
}
],
"ip_version": 4,
"gateway_ip": "192.168.10.1",
"cidr": "192.168.10.0/24"
}
}' https://api.vietnix.cloud:9696/v2.0/subnets
Using HTTP request
POST https://api.vietnix.cloud:9696/v2.0/subnets
Response
Response parameters
| Name | Type | Description |
|---|---|---|
subnet | object | A subnet object. |
id | string | The ID of the subnet. |
tenant_id | string | The ID of the project. |
project_id | string | The ID of the project. |
name | string | Human-readable name of the resource. |
description | string | Human-readable description. |
enable_dhcp | boolean | Whether DHCP is enabled for the subnet. |
network_id | string | The ID of the network to which the subnet belongs. |
dns_nameservers | array | List of DNS name servers associated with the subnet. |
allocation_pools | array | Allocation pools with start and end IP addresses. |
host_routes | array | Additional routes with destination and nexthop. |
ip_version | integer | IP protocol version. 4 or 6. |
gateway_ip | string | Gateway IP of this subnet, or null. |
cidr | string | The CIDR of the subnet. |
created_at | string | Creation time (ISO 8601). |
updated_at | string | Last update time (ISO 8601) or null. |
ipv6_address_mode | string | IPv6 address mode or null. |
ipv6_ra_mode | string | IPv6 router advertisement mode or null. |
revision_number | integer | Revision number. |
segment_id | string | Associated network segment ID, if any. |
subnetpool_id | string | Subnet pool ID, if any. |
service_types | array | Service types associated with the subnet. |
tags | array | List of tags on the resource. |
dns_publish_fixed_ip | boolean | Whether to publish DNS records for IPs from this subnet. |
Sample responses
Subnet for a private network
{
"subnet": {
"id": "d3f93e1c-f59d-40f8-a46c-ea6285f3a069",
"name": "",
"tenant_id": "f33507157a634f1cac71e06a70fb558e",
"network_id": "170546a1-a70a-40af-93e2-9261c7c05b77",
"ip_version": 4,
"subnetpool_id": null,
"enable_dhcp": true,
"ipv6_ra_mode": null,
"ipv6_address_mode": null,
"gateway_ip": "192.168.10.1",
"cidr": "192.168.10.0/24",
"allocation_pools": [
{
"start": "192.168.10.2",
"end": "192.168.10.254"
}
],
"host_routes": [],
"dns_nameservers": [
"10.30.0.27",
"10.30.0.28"
],
"description": "",
"service_types": [],
"tags": [],
"created_at": "2025-09-23T07:00:56Z",
"updated_at": "2025-09-23T07:00:56Z",
"revision_number": 0,
"project_id": "f33507157a634f1cac71e06a70fb558e"
}
}
Status codes
Success
| Status Code | Description |
|---|---|
| 201 - Created | Resource was created and is ready to use. |
Error
| Status Code | Description |
|---|---|
| 400 - Bad Request | Some content in the request was invalid. |
| 401 - Unauthorized | User must authenticate before making a request. |
| 403 - Forbidden | Policy does not allow current user to do this operation. |
| 404 - Not Found | The requested resource could not be found. |
| 409 - Conflict | This operation conflicted with another operation on this resource. |