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​

subnetobjectrequired

A subnet object.

tenant_idstring

The ID of the project that owns the resource. Admin/advsvc can specify a different project.

project_idstring

The ID of the project that owns the resource. Admin/advsvc can specify a different project.

namestring

Human-readable name of the subnet.

descriptionstring

Human-readable description.

enable_dhcpboolean

Whether DHCP is enabled for the subnet. Default: true.

network_idstringrequired

The ID of the network to which the subnet belongs.

dns_nameserversarray

List of DNS name servers associated with the subnet.

allocation_poolsarray

Allocation pools with start and end IP addresses for this subnet. If omitted, pools are auto-allocated (excluding gateway).

host_routesarray

Additional routes. Each item has destination and nexthop.

ip_versionintegerrequired

IP protocol version. 4 or 6.

gateway_ipstring

Gateway IP of this subnet. Use null to create without a gateway. If omitted, an address is allocated from the CIDR.

cidrstringrequired

The CIDR of the subnet.

prefixleninteger

Prefix length to use for allocation from a subnet pool.

ipv6_address_modestring

IPv6 address assignment mode: slaac, dhcpv6-stateful, dhcpv6-stateless.

ipv6_ra_modestring

IPv6 router advertisement mode: slaac, dhcpv6-stateful, dhcpv6-stateless.

segment_idstring

The ID of a network segment the subnet is associated with.

subnetpool_idstring

The ID of the subnet pool associated with the subnet.

use_default_subnetpoolboolean

Whether to allocate this subnet from the default subnet pool.

service_typesarray

Service types associated with the subnet.

dns_publish_fixed_ipboolean

Whether to publish DNS records for IPs from this subnet. Default: false.

Example requests​

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

Response​

Response parameters​

subnetobjectrequired

A subnet object.

idstringrequired

The ID of the subnet.

tenant_idstringrequired

The ID of the project.

project_idstringrequired

The ID of the project.

namestringrequired

Human-readable name of the resource.

descriptionstringrequired

Human-readable description.

enable_dhcpbooleanrequired

Whether DHCP is enabled for the subnet.

network_idstringrequired

The ID of the network to which the subnet belongs.

dns_nameserversarrayrequired

List of DNS name servers associated with the subnet.

allocation_poolsarrayrequired

Allocation pools with start and end IP addresses.

host_routesarrayrequired

Additional routes with destination and nexthop.

ip_versionintegerrequired

IP protocol version. 4 or 6.

gateway_ipstringrequired

Gateway IP of this subnet, or null.

cidrstringrequired

The CIDR of the subnet.

created_atstringrequired

Creation time (ISO 8601).

updated_atstringrequired

Last update time (ISO 8601) or null.

ipv6_address_modestringrequired

IPv6 address mode or null.

ipv6_ra_modestringrequired

IPv6 router advertisement mode or null.

revision_numberintegerrequired

Revision number.

segment_idstringrequired

Associated network segment ID, if any.

subnetpool_idstringrequired

Subnet pool ID, if any.

service_typesarrayrequired

Service types associated with the subnet.

tagsarrayrequired

List of tags on the resource.

dns_publish_fixed_ipbooleanrequired

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