OpenStack CLI subnet commands for IPv4 and IPv6
Assumptions made here:
- The public network has already been created
- That by doing a
openstack subnet listthere are no existing subnets named public-v6 or public1 - You have already installed the Openstack CLI client LINK using your preferred method.
- You are not using the individual project CLI client for instance Neutron in this case but instead the common client.
- That you are using the default gw of the first usable address in the subnet. If not you can manually select the gateway here
--gateway 192.168.1.254
OpenStack CLI Commands
For IPv4
Run the following command to create an IPv4 subnet with an explicit DHCP allocation pool:
openstack subnet create --network public --allocation-pool start=192.168.1.2,end=192.168.1.254 --subnet-range 192.168.1.0/24 public1For IPv6 (SLAAC)
Run the following command to create an IPv6 SLAAC subnet on the same network:
openstack subnet create --dhcp --network public --ip-version 6 --ipv6-address-mode slaac --subnet-range 2600:100:1:1::/64 public-v6Confirmation of OpenStack CLI subnet Commands
You can confirm that you have created the subnets by using the OpenStack CLI subnet commands to show you your subnets. You will issue the following commands in order to the see the subnets from the CLI:
jfarr@nertwork1:~$ openstack subnet list
+--------------------------------------+----------+--------------------------------------+-----------------+
| ID | Name | Network | Subnet |
+--------------------------------------+----------+--------------------------------------+-----------------+
| 0dc86c16-f87b-4edf-b746-8832e7689444 | public1 | 75de19cb-cb43-42ff-97a2-847fc79fff3e | 192.168.0.0/24 |Here you will see your subnet, if you want more information you can issue the following commands:
openstack subnet show public1Your output will be seen below:
jfarr@nertwork1:~$ openstack subnet show public1
+-------------------------+--------------------------------------+
| Field | Value |
+-------------------------+--------------------------------------+
| allocation_pools | 192.168.0.2-192.168.0.254 |
| cidr | 192.168.0.0/24 |
| created_at | 2017-12-05T19:51:53Z |
| description | |
| dns_nameservers | 8.8.8.8 |
| enable_dhcp | True |
| gateway_ip | 192.168.0.1 |
| host_routes | |
TRUNCATEDOpenStack CLI Commands Reference
Public subnets and networks do not actually mean public to the outside world in this guide. What they mean in this guide is that these networks can be accessed by anything outside of OpenStack that is routed to the OpenStack cluster. In this sense they are public networks.
Having the legacy
neutron subnet-createsyntax side-by-side with the modern unifiedopenstack subnet create --subnet-rangeCLI flags is super helpful when maintaining older Queens/Rocky clouds alongside Yoga.Don't forget
--ipv6-ra-mode slaac --ipv6-address-mode slaacwhen creating the/64IPv6 tenant subnet in Neutron so guest instances auto-configure their default gateway via Router Advertisements!