Creating and Managing Networks Using the CLI

A network allows connected resources to communicate. A router directs network traffic between different networks and is required for accessing instances on a private network from the external network. This topic provides basic instructions on creating a network and a router. For more information on networks, refer to the Networking Overview. For more information on creating a private network for launching instances, see Creating a Network for Instances.

Prerequisites—You must prepare your environment to access the command-line interface:

Creating a Network

$ openstack network create <NETWORK_NAME>
+---------------------------+-----------------------+
| Field                     | Value                 |
+---------------------------+-----------------------+
| admin_state_up            | UP                    |
| availability_zone_hints   | None                  |
| availability_zones        | None                  |
| created_at                | None                  |
| description               | None                  |
| dns_domain                | None                  |
| id                        | <network_id>          |
| ipv4_address_scope        | None                  |
| ipv6_address_scope        | None                  |
| is_default                | None                  |
| is_vlan_transparent       | None                  |
| mtu                       | 0                     |
| name                      | <network_name>        |
| port_security_enabled     | False                 |
| project_id                | None                  |
| provider:network_type     | None                  |
| provider:physical_network | None                  |
| provider:segmentation_id  | None                  |
| qos_policy_id             | None                  |
| revision_number           | None                  |
| router:external           | Internal              |
| segments                  | None                  |
| shared                    | False                 |
| status                    | ACTIVE                |
| subnets                   |                       |
| updated_at                | None                  |
+---------------------------+-----------------------+

Note
Some fields of the created network are only visible to administrators.

Creating a Subnet

$ openstack subnet create <SUBNET_NAME> --network <NETWORK_NAME> --subnet-range <CIDR>

The subnet create command uses the following parameters:

  • NETWORK_NAME—The name or ID of the network to which the subnet belongs.
  • CIDR—The CIDR of the subnet, for example 192.168.2.0/24.
  • SUBNET_NAME—The name of the subnet.

For information on the advanced use of the subnet subcommand (with examples), see the Administrator Guide.

Creating a Router

$ openstack router create <ROUTER_NAME>

Note
If you receive an error message, verify the router name is not identical to an existing router.

The unique router identifier returned is required to perform the following steps. Replace ROUTER_ID with the unique identifier of the router, and replace NETWORK_ID with the unique identifier of the external provider network.

To set the gateway for the router to reach the public network:

$ openstack router set <ROUTER_ID> --external-gateway <NETWORK_ID>
$ openstack router add subnet <ROUTER_ID> <SUBNET_ID>

Creating Ports

When you create a port without specifying an IP address, the system allocates a MAC address and applies a DOWN status.

$ openstack port create <PORT_NAME> --network <NETWORK_ID>

To create a port with a specified IP address:

$ openstack port create <PORT_NAME> --network <NETWORK_ID> --fixed-ip subnet=<SUBNET_ID>,ip_address=0.0.0.0

Note
When you create a port, you can specify any unallocated IP in the subnet even if the address is not in a pre-defined pool of allocated IP addresses (set by your cloud provider).

To query a port with a fixed IP address:

$ openstack port list --fixed-ip ip-address=192.168.2.2
+------------+------+-------------------+---------------------------------------------------+--------+
| ID         | Name | MAC Address       | Fixed IP Addresses                                | Status |
+------------+------+-------------------+---------------------------------------------------+--------+
| <port_id>  |      | fa:16:3e:d7:07:ae | ip_address='192.168.8.2', subnet_id='<subnet_id>' | ACTIVE |
+------------+------+-------------------+---------------------------------------------------+--------+