Create a subnet

Create a subnet to divide and isolate network traffic.

Before you begin

  • The administrator has created a project for you and has provided you with a clouds.yaml file for you to access the cloud.
  • The python-openstackclient package is on your workstation.
    $ dnf list installed python-openstackclient

About this task

Subnets logically divide a network to provide efficiency and isolation.

Instances that use the same subnet can communicate without passing data traffic through a router. Locating systems that require a high volume of traffic between them in the same subnet avoids the subsequent latency and load.

By using different subnets for different purposes, you can isolate data traffic. For example, web server traffic might use one subnet, and database traffic might use another subnet. Instances that want to communicate with instances in another subnet must direct their data traffic through a router.

Procedure

  1. Confirm that the system OS_CLOUD variable is set for your cloud:
    $ echo $OS_CLOUD
    my_cloud

    Reset the variable if necessary:

    $ export OS_CLOUD=my_other_cloud

    As an alternative, you can specify the cloud name by adding the --os-cloud <cloud_name> option each time you run an openstack command.

  2. Obtain the name of the network to which you want to add a subnet:
    $ openstack network list
  3. Create a subnet.
    $ openstack subnet create <subnet-name> --subnet-range <CIDR> --network <name>
    • Replace <subnet-name> with the name of the subnet you are creating.
    • Replace <CIDR> with the IP address range and subnet mask in CIDR format.

      To determine the CIDR address, calculate the number of bits masked in the subnet mask and append that value to the IP address range. For example, the subnet mask 255.255.255.0 has 24 masked bits. To use this mask with the IPv4 address range 192.168.122.0, specify the address 192.168.122.0/24.

    • Replace <name> with the name of the network to which you are adding the subnet. Tip

      DHCP services automate the distribution of IP settings to your instances and is enabled by default. Specify --no-dhcp to disable DHCP.

Results

  • Confirm that the subnet was added:
    $ openstack subnet list -c Name -c Network -c Subnet --max-width=72
    Sample output
    +----------------------+-------------------------+---------------------+
    | Name                 | Network                 | Subnet              |
    +----------------------+-------------------------+---------------------+
    | private_subnet24     | 317be3d3-5265-43f7-b52b | 10.0.24.0/24        |
    |                      | -930e3fd19b8b           |                     |
    | lb-mgmt-subnet       | c4588d49-9151-414b-8832 | 172.24.0.0/16       |
    |                      | -37313e3b4c57           |                     |
    | external_subnet      | bcdb3cc0-8c0b-4d2d-813c | 10.0.0.0/24         |
    |                      | -e141bb97aa8f           |                     |
    | external_ipv6_subnet | bcdb3cc0-8c0b-4d2d-813c | 2620:52:0:13b8::/64 |
    |                      | -e141bb97aa8f           |                     |
    | private_subnet       | 317be3d3-5265-43f7-b52b | 10.0.1.0/24         |
    |                      | -930e3fd19b8b           |                     |
    +----------------------+-------------------------+---------------------+

    When you create instances, you can configure them now to use its subnet, and they receive any specified DHCP options.

What to do next

  • If you need to modify the subnet, use the openstack subnet set command.

Multi-tenancy networking with subnets

Plan your subnets to provide secure, efficient multi-tenancy networking.

Subnets enable network connectivity to instances. A subnet is a pool of IP addresses. Instances are assigned to a Networking service (neutron) network. One network can have multiple subnets, and you can also add IP addresses from multiple subnets to the port.

You can create subnets only in pre-existing networks. Project networks in the Networking service can host multiple subnets. This is useful if you intend to host distinctly different systems in the same network, and prefer a measure of isolation between them.

You can decrease network latency and load by grouping systems in the same subnet that require a high volume of traffic between each other.

Create an IPv6 subnet with Stateful DHCPv6

Create an IPv6 subnet by using Stateful DHCPv6.

Before you begin

  • The administrator has created a project for you and has provided you with a clouds.yaml file for you to access the cloud.
  • The python-openstackclient package is on your workstation.
    $ dnf list installed python-openstackclient

Procedure

  1. Confirm that the system OS_CLOUD variable is set for your cloud:
    $ echo $OS_CLOUD
    my_cloud

    Reset the variable if necessary:

    $ export OS_CLOUD=my_other_cloud

    As an alternative, you can specify the cloud name by adding the --os-cloud <cloud_name> option each time you run an openstack command.

  2. Obtain the project ID of the project where you want to create the IPv6 subnet.

    Retain this ID, because you will need it later:

    $ openstack project list
    Sample output
    +----------------------------------+----------+
    | ID                               | Name     |
    +----------------------------------+----------+
    | 25837c567ed5458fbb441d39862e1399 |    QA    |
    | f59f631a77264a8eb0defc898cb836af |  admin   |
    | 4e2e1951e70643b5af7ed52f3ff36539 |   demo   |
    | 8561dff8310e4cd8be4b6fd03dc8acf5 | services |
    +----------------------------------+----------+
  3. Obtain the name of the network where you want to host the IPv6 subnet.

    Retain this name, because you will need it later:

    $ openstack network list -c Name -c Subnets --max-width=72
    Sample output
    +-------------+--------------------------------------------------------+
    | Name        | Subnets                                                |
    +-------------+--------------------------------------------------------+
    | private     | 47d34cf0-0dd2-49bd-a985-67311d80c5c4,                  |
    |             | 82014d36-9e60-43eb-92fc-74674573f4e8,                  |
    |             | d7535565-113f-4192-baa6-da21f301f141                   |
    | private2    | 7ee56cef-83c0-40d1-b4e7-5287dae1c23c                   |
    | public      | 6745edd4-d15f-4971-89bf-70307b0ad2f1,                  |
    |             | cc3f81bb-4d55-4ead-aad4-5362a7ca5b04                   |
    | lb-mgmt-net | 5ca08724-568c-4030-93eb-f2e286570a25                   |
    +-------------+--------------------------------------------------------+
  4. Using the project ID and network name, create an IPv6 subnet:
    Example
    $ openstack subnet create --ip-version 6 --ipv6-address-mode \
    dhcpv6-stateful --project 25837c567ed5458fbb441d39862e1399 \
    --network private2 --subnet-range fdf8:f53b:82e4::53/125 \
    subnet_name
    Sample output
    +-------------------+--------------------------------------------------------------+
    | Field             | Value                                                        |
    +-------------------+--------------------------------------------------------------+
    | allocation_pools  | {"start": "fdf8:f53b:82e4::52", "end": "fdf8:f53b:82e4::56"} |
    | cidr              | fdf8:f53b:82e4::53/125                                       |
    | dns_nameservers   |                                                              |
    | enable_dhcp       | True                                                         |
    | gateway_ip        | fdf8:f53b:82e4::51                                           |
    | host_routes       |                                                              |
    | id                | cdfc3398-997b-46eb-9db1-ebbd88f7de05                         |
    | ip_version        | 6                                                            |
    | ipv6_address_mode | dhcpv6-stateful                                              |
    | ipv6_ra_mode      |                                                              |
    | name              |                                                              |
    | network_id        | 6aff6826-4278-4a35-b74d-b0ca0cbba340                         |
    | tenant_id         | 25837c567ed5458fbb441d39862e1399                             |
    +-------------------+--------------------------------------------------------------+

Results

  1. Validate this configuration by reviewing the network list.
    $ openstack network list -c Name -c Subnets --max-width=72
    Sample output

    Note that the entry for private2 now reflects the newly created IPv6 subnet:

    +-------------+--------------------------------------------------------+
    | Name        | Subnets                                                |
    +-------------+--------------------------------------------------------+
    | private     | 47d34cf0-0dd2-49bd-a985-67311d80c5c4,                  |
    |             | 82014d36-9e60-43eb-92fc-74674573f4e8,                  |
    |             | d7535565-113f-4192-baa6-da21f301f141                   |
    | private2    | 7ee56cef-83c0-40d1-b4e7-5287dae1c23c,                  |
    |             | cdfc3398-997b-46eb-9db1-ebbd88f7de05                   |
    | public      | 6745edd4-d15f-4971-89bf-70307b0ad2f1,                  |
    |             | cc3f81bb-4d55-4ead-aad4-5362a7ca5b04                   |
    | lb-mgmt-net | 5ca08724-568c-4030-93eb-f2e286570a25                   |
    +-------------+--------------------------------------------------------+
  2. Create an instance, and confirm that the instance is associated with a DHCP IPv6 address when added to the private2 subnet:
    $ openstack server list -c Name -c Status -c Networks
    Sample output
    +---------+--------+-----------------------------+
    | Name    | Status | Networks                    |
    +---------+--------+-----------------------------+
    | server1 | ACTIVE | private2=fdf8:f53b:82e4::52 |
    +---------+--------+-----------------------------+

IPv6 subnet configuration options

Review IPv6 subnet address and router advertisement mode options.

Note

RHOSO does not support IPv6 prefix delegation from an external entity. You must obtain the Global Unicast Address (GUA) prefix from your external prefix delegation router and set it by using the subnet-range argument during creation of a IPv6 subnet.

Example
$ openstack subnet create --ip-version 6\
--subnet-range 2002:c000:200::64 \
--no-dhcp \
--gateway 2002:c000:2fe:: \
--dns-nameserver 2002:c000:2fe:: \
--network provider \
provider-subnet-2002:c000:200::
Sample output
+----------------------+--------------------------------------+
| Field                | Value                                |
+----------------------+--------------------------------------+
| allocation_pools     | 2002:c000:200::64-2002:c000:200::64  |
| cidr                 | 2002:c000:200::64/128                |
| created_at           | 2024-09-24T19:30:07Z                 |
| description          |                                      |
| dns_nameservers      | 2002:c000:2fe::                      |
| dns_publish_fixed_ip | None                                 |
| enable_dhcp          | False                                |
| gateway_ip           | 2002:c000:200::64                    |
| host_routes          |                                      |
| id                   | 49dda67d-814e-457b-b14b-77ef32935c0f |
| ip_version           | 6                                    |
| ipv6_address_mode    | None                                 |
| ipv6_ra_mode         | None                                 |
| name                 | provider-subnet-2002:c000:200::      |
| network_id           | bcdb3cc0-8c0b-4d2d-813c-e141bb97aa8f |
| prefix_length        | None                                 |
| project_id           | 24089d2fe1a94dd29ca2f665794fbe92     |
| revision_number      | 0                                    |
| segment_id           | None                                 |
| service_types        | None                                 |
| subnetpool_id        | None                                 |
| tags                 |                                      |
| updated_at           | 2024-09-24T19:30:07Z                 |
+----------------------+--------------------------------------+
Expand
RA Mode Address Mode Result

ipv6_ra_mode=not set

ipv6-address-mode=slaac

The instance receives an IPv6 address from the external router (not managed by OpenStack Networking) using stateless address autoconfiguration (SLAAC).

Note

The RHOSO Networking service (neutron) supports only EUI-64 IPv6 address assignment for SLAAC. This allows for simplified IPv6 networking, as hosts self-assign addresses based on the base 64-bits plus the MAC address. You cannot create subnets with a different netmask and address_assign_type of SLAAC.

ipv6_ra_mode=not set

ipv6-address-mode=dhcpv6-stateful

The instance receives an IPv6 address and optional information from the Networking service (dnsmasq) using DHCPv6 stateful.

ipv6_ra_mode=not set

ipv6-address-mode=dhcpv6-stateless

The instance receives an IPv6 address from the external router using SLAAC, and optional information from the Networking service (dnsmasq) using DHCPv6 stateless.

ipv6_ra_mode=slaac

ipv6-address-mode=not-set

The instance uses SLAAC to receive an IPv6 address from the Networking service (radvd).

ipv6_ra_mode=dhcpv6-stateful

ipv6-address-mode=not-set

The instance receives an IPv6 address and optional information from an external DHCPv6 server using DHCPv6 stateful.

ipv6_ra_mode=dhcpv6-stateless

ipv6-address-mode=not-set

The instance receives an IPv6 address from the Networking service (radvd) using SLAAC, and optional information from an external DHCPv6 server using DHCPv6 stateless.

ipv6_ra_mode=slaac

ipv6-address-mode=slaac

The instance receives an IPv6 address from the Networking service (radvd) using SLAAC.

ipv6_ra_mode=dhcpv6-stateful

ipv6-address-mode=dhcpv6-stateful

The instance receives an IPv6 address from OpenStack Networking (dnsmasq) using DHCPv6 stateful, and optional information from OpenStack Networking (dnsmasq) using DHCPv6 stateful.

ipv6_ra_mode=dhcpv6-stateless

ipv6-address-mode=dhcpv6-stateless

The instance receives an IPv6 address from OpenStack Networking (radvd) using SLAAC, and optional information from OpenStack Networking (dnsmasq) using DHCPv6 stateless.

Remove an unused subnet

Delete a subnet that is no longer in use.

Before you begin

  • The administrator has created a project for you and has provided you with a clouds.yaml file for you to access the cloud.
  • The python-openstackclient package is on your workstation.
    $ dnf list installed python-openstackclient
  • No instances are configured to use the subnet that you want to delete.

Procedure

  1. Confirm that the system OS_CLOUD variable is set for your cloud:
    $ echo $OS_CLOUD
    my_cloud

    Reset the variable if necessary:

    $ export OS_CLOUD=my_other_cloud

    As an alternative, you can specify the cloud name by adding the --os-cloud <cloud_name> option each time you run an openstack command.

  2. Obtain the name of the subnet that you want to delete.

    Retain this name, because you will need it later.

    $ openstack subnet list
    Sample output
    +----------------------+-------------------------+---------------------+
    | Name                 | Network                 | Subnet              |
    +----------------------+-------------------------+---------------------+
    | private_subnet24     | 317be3d3-5265-43f7-b52b | 10.0.24.0/24        |
    |                      | -930e3fd19b8b           |                     |
    | lb-mgmt-subnet       | c4588d49-9151-414b-8832 | 172.24.0.0/16       |
    |                      | -37313e3b4c57           |                     |
    | external_subnet      | bcdb3cc0-8c0b-4d2d-813c | 10.0.0.0/24         |
    |                      | -e141bb97aa8f           |                     |
    | private2_subnet      | 56e73380-a771-408f-bdc0 | 10.1.2.0/24         |
    |                      | -1e97f79677c6           |                     |
    | private_subnet2      | 317be3d3-5265-43f7-b52b | 10.0.2.0/24         |
    |                      | -930e3fd19b8b           |                     |
    | external_ipv6_subnet | bcdb3cc0-8c0b-4d2d-813c | 2620:52:0:13b8::/64 |
    |                      | -e141bb97aa8f           |                     |
    | private_subnet       | 317be3d3-5265-43f7-b52b | 10.0.1.0/24         |
    |                      | -930e3fd19b8b           |                     |
    +----------------------+-------------------------+---------------------+
  3. Using the subnet name, delete the subnet.
    Example

    In this example, private_subnet24 is deleted:

    $ openstack subnet delete private_subnet24

Results

  • Confirm that the subnet was deleted:
    $ openstack subnet list -c Name -c Network -c Subnet --max-width=72
    Sample output
    +----------------------+-------------------------+---------------------+
    | Name                 | Network                 | Subnet              |
    +----------------------+-------------------------+---------------------+
    | lb-mgmt-subnet       | c4588d49-9151-414b-8832 | 172.24.0.0/16       |
    |                      | -37313e3b4c57           |                     |
    | external_subnet      | bcdb3cc0-8c0b-4d2d-813c | 10.0.0.0/24         |
    |                      | -e141bb97aa8f           |                     |
    | private2_subnet      | 56e73380-a771-408f-bdc0 | 10.1.2.0/24         |
    |                      | -1e97f79677c6           |                     |
    | private_subnet2      | 317be3d3-5265-43f7-b52b | 10.0.2.0/24         |
    |                      | -930e3fd19b8b           |                     |
    | external_ipv6_subnet | bcdb3cc0-8c0b-4d2d-813c | 2620:52:0:13b8::/64 |
    |                      | -e141bb97aa8f           |                     |
    | private_subnet       | 317be3d3-5265-43f7-b52b | 10.0.1.0/24         |
    |                      | -930e3fd19b8b           |                     |
    +----------------------+-------------------------+---------------------+