OpenStack | Subnets
command syntax: openstack subnet <action/operation> <--flags values> <subnet-name>
action/operation : list, create, show, delete...
flags: no-dhcp, gateway, long, network, subnet-range...
#to view the list of subnets
cumulus@server01:~$ openstack subnet list
+--------------------------------------+----------+--------------------------------------+----------------+
| ID | Name | Network| Subnet |
+--------------------------------------+----------+--------------------------------------+----------------+
| c679c440-8286-4eeb-8025-19e0c0895aef | provider | dc005f68-35c6-4151-ad18-ac21523ed4e5| 192.168.0.0/24 |
+--------------------------------------+----------+--------------------------------------+----------------+
#to get a detailed info of the subnet list
cumulus@server01:~$ openstack subnet list --long
+--------------------------------------+----------+--------------------------------------+----------------+----------------------------------+------+--------------+-----------------------------+-------------+------------+---------------+---------------+------+
| ID | Name | Network
| Subnet | Project | DHCP | Name Servers | Allocation Pools | Host Routes | IP Version | Gateway | Service Types | Tags |
+--------------------------------------+----------+--------------------------------------+----------------+----------------------------------+------+--------------+-----------------------------+-------------+------------+---------------+---------------+------+
| c679c440-8286-4eeb-8025-19e0c0895aef | provider | dc005f68-35c6-4151-ad18-ac21523ed4e5
| 192.168.0.0/24 | 6d9cb60806744bbc9618963e77bda3cd | True | 8.8.4.4 | 192.168.0.100
-192.168.0.150 | | 4 | 192.168.0.254 | | |
+--------------------------------------+----------+--------------------------------------+----------------+----------------------------------+------+--------------+-----------------------------+-------------+------------+---------------+---------------+------+
#let's create a new subnet, we need to map it with the appropriate network name (already created), and the network IP with prefix
cumulus@server01:~$ openstack subnet create --network firstNetwork --subnet-range 192.168.1.0/24 firstSubnet
+-------------------------+--------------------------------------+
| Field | Value |
+-------------------------+--------------------------------------+
| allocation_pools | 192.168.1.2-192.168.1.254 |
| cidr | 192.168.1.0/24 |
| created_at | 2018-07-10T05:24:44Z |
| description | |
| dns_nameservers | |
| enable_dhcp | True |
| gateway_ip | 192.168.1.1 |
| host_routes | |
| id | 6ebf3ecb-caac-4c24-80aa-953a04bc23a8 |
| ip_version | 4 |
| ipv6_address_mode | None |
| ipv6_ra_mode | None |
| name | firstSubnet |
| network_id | dfb787e9-25e6-4e0d-996f-4619ba3b360d |
| project_id | 6d9cb60806744bbc9618963e77bda3cd |
| revision_number | 0 |
| segment_id | None |
| service_types | |
| subnetpool_id | None |
| tags | |
| updated_at | 2018-07-10T05:24:44Z |
| use_default_subnet_pool | None |
+-------------------------+--------------------------------------+
cumulus@server01:~$
#to verify
cumulus@server01:~$ openstack subnet list --long | grep firstSubnet
| 6ebf3ecb-caac-4c24-80aa-953a04bc23a8 | firstSubnet | dfb787e9-25e6-4e0d-996f-4619ba3b360d | 192.168.1.0/24 | 6d9cb60806744bbc9618963e77bda3cd | True | | 192.168.1.2-192.168.1.254 | | 4 | 192.168.1.1 | | |
cumulus@server01:~$
#Note that, by default, if not specified DHCP will be enabled on the subnet, and the first IP of the network will be chosen as the default gateway
#let's create a subnet, for the external network
cumulus@server01:~$ openstack subnet create --network firstProviderNetwork --subnet-range 192.168.2.0/24 --no-dhcp firstProviderSubnet
+-------------------------+--------------------------------------+
| Field | Value |
+-------------------------+--------------------------------------+
| allocation_pools | 192.168.2.2-192.168.2.254 |
| cidr | 192.168.2.0/24 |
| created_at | 2018-07-10T05:52:19Z |
| description | |
| dns_nameservers | |
| enable_dhcp | False |
| gateway_ip | 192.168.2.1 |
| host_routes | |
| id | eff1b2c9-7169-4f41-8d68-8d40cca3d3d3 |
| ip_version | 4 |
| ipv6_address_mode | None |
| ipv6_ra_mode | None |
| name | firstProviderSubnet |
| network_id | 1a135cc1-f5c6-489d-9378-353424bbb4fc |
| project_id | 6d9cb60806744bbc9618963e77bda3cd |
| revision_number | 0 |
| segment_id | None |
| service_types | |
| subnetpool_id | None |
| tags | |
| updated_at | 2018-07-10T05:52:19Z |
| use_default_subnet_pool | None |
+-------------------------+--------------------------------------+
--end-of-post--