Create Subnet
/v2.0/subnetsCreate 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
subnetobjectrequiredA subnet object.
tenant_idstringThe ID of the project that owns the resource. Admin/advsvc can specify a different project.
project_idstringThe ID of the project that owns the resource. Admin/advsvc can specify a different project.
namestringHuman-readable name of the subnet.
descriptionstringHuman-readable description.
enable_dhcpbooleanWhether DHCP is enabled for the subnet. Default: true.
network_idstringrequiredThe ID of the network to which the subnet belongs.
dns_nameserversarrayList of DNS name servers associated with the subnet.
allocation_poolsarrayAllocation pools with start and end IP addresses for this subnet. If omitted, pools are auto-allocated (excluding gateway).
host_routesarrayAdditional routes. Each item has destination and nexthop.
ip_versionintegerrequiredIP protocol version. 4 or 6.
gateway_ipstringGateway IP of this subnet. Use null to create without a gateway. If omitted, an address is allocated from the CIDR.
cidrstringrequiredThe CIDR of the subnet.
prefixlenintegerPrefix length to use for allocation from a subnet pool.
ipv6_address_modestringIPv6 address assignment mode: slaac, dhcpv6-stateful, dhcpv6-stateless.
ipv6_ra_modestringIPv6 router advertisement mode: slaac, dhcpv6-stateful, dhcpv6-stateless.
segment_idstringThe ID of a network segment the subnet is associated with.
subnetpool_idstringThe ID of the subnet pool associated with the subnet.
use_default_subnetpoolbooleanWhether to allocate this subnet from the default subnet pool.
service_typesarrayService types associated with the subnet.
dns_publish_fixed_ipbooleanWhether to publish DNS records for IPs from this subnet. Default: false.
Example requests
- cURL
- HTTP
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
POST https://api.vietnix.cloud:9696/v2.0/subnets
Response
Response parameters
subnetobjectrequiredA subnet object.
idstringrequiredThe ID of the subnet.
tenant_idstringrequiredThe ID of the project.
project_idstringrequiredThe ID of the project.
namestringrequiredHuman-readable name of the resource.
descriptionstringrequiredHuman-readable description.
enable_dhcpbooleanrequiredWhether DHCP is enabled for the subnet.
network_idstringrequiredThe ID of the network to which the subnet belongs.
dns_nameserversarrayrequiredList of DNS name servers associated with the subnet.
allocation_poolsarrayrequiredAllocation pools with start and end IP addresses.
host_routesarrayrequiredAdditional routes with destination and nexthop.
ip_versionintegerrequiredIP protocol version. 4 or 6.
gateway_ipstringrequiredGateway IP of this subnet, or null.
cidrstringrequiredThe CIDR of the subnet.
created_atstringrequiredCreation time (ISO 8601).
updated_atstringrequiredLast update time (ISO 8601) or null.
ipv6_address_modestringrequiredIPv6 address mode or null.
ipv6_ra_modestringrequiredIPv6 router advertisement mode or null.
revision_numberintegerrequiredRevision number.
segment_idstringrequiredAssociated network segment ID, if any.
subnetpool_idstringrequiredSubnet pool ID, if any.
service_typesarrayrequiredService types associated with the subnet.
tagsarrayrequiredList of tags on the resource.
dns_publish_fixed_ipbooleanrequiredWhether to publish DNS records for IPs from this subnet.
Sample responses
Subnet for a private network
Response body
{
"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. |