Creating and Managing Networks Using the CLI

This provides basic instructions on creating a network and a router. For more information on networks, refer to the Neutron 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

List the extensions of the system adding a column for alias and a column for name.

$ neutron ext-list -c alias -c name
+----------------------------+---------------------------------------+
| alias                      | name                                  |
+----------------------------+---------------------------------------+
| router_ha                  | High-availability for routing service |
| dns-integration            | DNS Integration                       |
| binding                    | Port Binding                          |
| agent                      | agent                                 |
| subnet_allocation          | Subnet Allocation                     |
| l3_agent_scheduler         | L3 Agent Scheduler                    |
| external-net               | Neutron external network              |
| flavors                    | Neutron Service Flavors               |
| cisco-cfg-agent-scheduler  | Cisco Configuration Agent Scheduler   |
| routertype-aware-scheduler | Cisco routertype aware Scheduler      |
| net-mtu                    | Network MTU                           |
| quotas                     | Quota management support              |
| provider                   | Provider Network                      |
| multi-provider             | Multi Provider Network                |
| extraroute                 | Neutron Extra Route                   |
| routerhost                 | Hosting info for routing service      |
| routertype                 | Router types for routing service      |
| extra_dhcp_opt             | Neutron Extra DHCP opts               |
| routerrole                 | Role info for routing service         |
| security-group             | security-group                        |
| dhcp_agent_scheduler       | DHCP Agent Scheduler                  |
| dev_mgr                    | Cisco hosting device manager          |
| rbac-policies              | RBAC Policies                         |
| router                     | Neutron L3 Router                     |
| allowed-address-pairs      | Allowed Address Pairs                 |
+----------------------------+---------------------------------------+

To create a network:

$ openstack network create <NETWORK_NAME>
+-------------+----------------------+
| Field       | Value                |
+-------------+----------------------+
| id          | <network_id>         |
| mtu         | 0                    |
| name        | <network_name>       |
| project_id  | <project_id>         |
| router_type | Internal             |
| shared      | False                |
| state       | UP                   |
| status      | ACTIVE               |
| subnets     |                      |
+-------------+----------------------+

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:

$ neutron router-gateway-set <ROUTER_ID> "PUBLIC DO NOT MODIFY"

Replace SUBNET_ID with the unique identifier of the subnet.

$ neutron router-interface-add <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 ports with fixed IP addresses:

$ neutron port-list --fixed-ips ip_address=192.168.2.2 ip_address=192.168.2.40
+-----------+------+-------------------+-------------------------------------------------+
| id        | name | mac_address       | fixed_ips                                       |
+-----------+------+-------------------+-------------------------------------------------+
| <port_id> |      | fa:16:3e:f6:ec:c7 | {"subnet_id"... ..."ip_address": "192.168.2.2"} |
| <port_id> |      | fa:16:3e:97:e0:fc | {"subnet_id"... ..."ip_address": "192.168.2.40"}|
+-----------+------+-------------------+-------------------------------------------------+