Skip to main content

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

info

Request

Body parameters

NameInTypeDescription
subnetbodyobjectA subnet object.
tenant_id (Optional)bodystringThe ID of the project that owns the resource. Admin/advsvc can specify a different project.
project_id (Optional)bodystringThe ID of the project that owns the resource. Admin/advsvc can specify a different project.
name (Optional)bodystringHuman-readable name of the subnet.
description (Optional)bodystringHuman-readable description.
enable_dhcp (Optional)bodybooleanWhether DHCP is enabled for the subnet. Default: true.
network_idbodystringThe ID of the network to which the subnet belongs.
dns_nameservers (Optional)bodyarrayList of DNS name servers associated with the subnet.
allocation_pools (Optional)bodyarrayAllocation pools with start and end IP addresses for this subnet. If omitted, pools are auto-allocated (excluding gateway).
host_routes (Optional)bodyarrayAdditional routes. Each item has destination and nexthop.
ip_versionbodyintegerIP protocol version. 4 or 6.
gateway_ip (Optional)bodystringGateway IP of this subnet. Use null to create without a gateway. If omitted, an address is allocated from the CIDR.
cidrbodystringThe CIDR of the subnet.
prefixlen (Optional)bodyintegerPrefix length to use for allocation from a subnet pool.
ipv6_address_mode (Optional)bodystringIPv6 address assignment mode: slaac, dhcpv6-stateful, dhcpv6-stateless.
ipv6_ra_mode (Optional)bodystringIPv6 router advertisement mode: slaac, dhcpv6-stateful, dhcpv6-stateless.
segment_id (Optional)bodystringThe ID of a network segment the subnet is associated with.
subnetpool_id (Optional)bodystringThe ID of the subnet pool associated with the subnet.
use_default_subnetpool (Optional)bodybooleanWhether to allocate this subnet from the default subnet pool.
service_types (Optional)bodyarrayService types associated with the subnet.
dns_publish_fixed_ip (Optional)bodybooleanWhether 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

NameTypeDescription
subnetobjectA subnet object.
idstringThe ID of the subnet.
tenant_idstringThe ID of the project.
project_idstringThe ID of the project.
namestringHuman-readable name of the resource.
descriptionstringHuman-readable description.
enable_dhcpbooleanWhether DHCP is enabled for the subnet.
network_idstringThe 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.
host_routesarrayAdditional routes with destination and nexthop.
ip_versionintegerIP protocol version. 4 or 6.
gateway_ipstringGateway IP of this subnet, or null.
cidrstringThe CIDR of the subnet.
created_atstringCreation time (ISO 8601).
updated_atstringLast update time (ISO 8601) or null.
ipv6_address_modestringIPv6 address mode or null.
ipv6_ra_modestringIPv6 router advertisement mode or null.
revision_numberintegerRevision number.
segment_idstringAssociated network segment ID, if any.
subnetpool_idstringSubnet pool ID, if any.
service_typesarrayService types associated with the subnet.
tagsarrayList of tags on the resource.
dns_publish_fixed_ipbooleanWhether 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 CodeDescription
201 - CreatedResource was created and is ready to use.

Error

Status CodeDescription
400 - Bad RequestSome content in the request was invalid.
401 - UnauthorizedUser must authenticate before making a request.
403 - ForbiddenPolicy does not allow current user to do this operation.
404 - Not FoundThe requested resource could not be found.
409 - ConflictThis operation conflicted with another operation on this resource.