创建和管理网路

创建和管理网路

Before you run commands, set environment variables using the OpenStack RC file.

创建网络

  1. 列出系统的扩展分区

    $ openstack extension list -c Alias -c Name --network
    +------------------------------------------+---------------------------+
    | Name                                     | Alias                     |
    +------------------------------------------+---------------------------+
    | Default Subnetpools                      | default-subnetpools       |
    | Network IP Availability                  | network-ip-availability   |
    | Auto Allocated Topology Services         | auto-allocated-topology   |
    | Neutron L3 Configurable external gateway | ext-gw-mode               |
    | Address scope                            | address-scope             |
    | Neutron Extra Route                      | extraroute                |
    +------------------------------------------+---------------------------+
    
  2. 创建网络

    $ openstack network create net1
    Created a new network:
    +---------------------------+--------------------------------------+
    | Field                     | Value                                |
    +---------------------------+--------------------------------------+
    | admin_state_up            | UP                                   |
    | availability_zone_hints   |                                      |
    | availability_zones        |                                      |
    | created_at                | 2016-12-21T08:32:54Z                 |
    | description               |                                      |
    | headers                   |                                      |
    | id                        | 180620e3-9eae-4ba7-9739-c5847966e1f0 |
    | ipv4_address_scope        | None                                 |
    | ipv6_address_scope        | None                                 |
    | mtu                       | 1450                                 |
    | name                      | net1                                 |
    | port_security_enabled     | True                                 |
    | project_id                | c961a8f6d3654657885226378ade8220     |
    | provider:network_type     | vxlan                                |
    | provider:physical_network | None                                 |
    | provider:segmentation_id  | 14                                   |
    | revision_number           | 3                                    |
    | router:external           | Internal                             |
    | shared                    | False                                |
    | status                    | ACTIVE                               |
    | subnets                   |                                      |
    | tags                      | []                                   |
    | updated_at                | 2016-12-21T08:32:54Z                 |
    +---------------------------+--------------------------------------+
    

    注解

    创建的网络的某些属性对于非管理员用户来说是不可见的

  3. 创建一个指定的provider类型的网络

    $ openstack network create net2 --provider-network-type vxlan
    Created a new network:
    +---------------------------+--------------------------------------+
    | Field                     | Value                                |
    +---------------------------+--------------------------------------+
    | admin_state_up            | UP                                   |
    | availability_zone_hints   |                                      |
    | availability_zones        |                                      |
    | created_at                | 2016-12-21T08:33:34Z                 |
    | description               |                                      |
    | headers                   |                                      |
    | id                        | c0a563d5-ef7d-46b3-b30d-6b9d4138b6cf |
    | ipv4_address_scope        | None                                 |
    | ipv6_address_scope        | None                                 |
    | mtu                       | 1450                                 |
    | name                      | net2                                 |
    | port_security_enabled     | True                                 |
    | project_id                | c961a8f6d3654657885226378ade8220     |
    | provider:network_type     | vxlan                                |
    | provider:physical_network | None                                 |
    | provider:segmentation_id  | 87                                   |
    | revision_number           | 3                                    |
    | router:external           | Internal                             |
    | shared                    | False                                |
    | status                    | ACTIVE                               |
    | subnets                   |                                      |
    | tags                      | []                                   |
    | updated_at                | 2016-12-21T08:33:34Z                 |
    +---------------------------+--------------------------------------+
    

创建子网

创建一个子网

$ openstack subnet create subnet1 --network net1
  --subnet-range 192.0.2.0/24
+-------------------+--------------------------------------+
| Field             | Value                                |
+-------------------+--------------------------------------+
| allocation_pools  | 192.0.2.2-192.0.2.254                |
| cidr              | 192.0.2.0/24                         |
| created_at        | 2016-12-22T18:47:52Z                 |
| description       |                                      |
| dns_nameservers   |                                      |
| enable_dhcp       | True                                 |
| gateway_ip        | 192.0.2.1                            |
| headers           |                                      |
| host_routes       |                                      |
| id                | a394689c-f547-4834-9778-3e0bb22130dc |
| ip_version        | 4                                    |
| ipv6_address_mode | None                                 |
| ipv6_ra_mode      | None                                 |
| name              | subnet1                              |
| network_id        | 180620e3-9eae-4ba7-9739-c5847966e1f0 |
| project_id        | c961a8f6d3654657885226378ade8220     |
| revision_number   | 2                                    |
| service_types     |                                      |
| subnetpool_id     | None                                 |
| updated_at        | 2016-12-22T18:47:52Z                 |
+-------------------+--------------------------------------+

``subnet-create``命令有以下必须和可选的参数

  • 网络子网的名称或标识编码

    这个示例中,“net1”是指定网络名称的一个位置参数

  • 子网的CIDR

    In this example, 192.0.2.0/24 is a positional argument that specifies the CIDR.

  • 子网名称是可选项

    在此示例中,“–name subnet1” 用于指定子网名称

For information and examples on more advanced use of neutron’s subnet subcommand, see the OpenStack Administrator Guide.

创建路由器

  1. 创建一个路由器

    $ openstack router create router1
    +-------------------------+--------------------------------------+
    | Field                   | Value                                |
    +-------------------------+--------------------------------------+
    | admin_state_up          | UP                                   |
    | availability_zone_hints |                                      |
    | availability_zones      |                                      |
    | created_at              | 2016-12-22T18:48:57Z                 |
    | description             |                                      |
    | distributed             | True                                 |
    | external_gateway_info   | null                                 |
    | flavor_id               | None                                 |
    | ha                      | False                                |
    | headers                 |                                      |
    | id                      | e25a24ee-3458-45c7-b16e-edf49092aab7 |
    | name                    | router1                              |
    | project_id              | e17431afc0524e0690484889a04b7fa0     |
    | revision_number         | 1                                    |
    | routes                  |                                      |
    | status                  | ACTIVE                               |
    | updated_at              | 2016-12-22T18:48:57Z                 |
    +-------------------------+--------------------------------------+
    

    注意唯一返回的路由器标识符将会在后续的步骤中使用到。

  2. 将路由器连接到外部的提供商网络

    $ openstack router set ROUTER --external-gateway NETWORK
    

    用路由器的唯一标识符替换ROUTER,用外部供应商网络的唯一标识符替换NETWORK 。

  3. 将路由器连接到子网:

    $ openstack router add subnet ROUTER SUBNET
    

    用路由器的唯一标识符替换ROUTER ,用子网的唯一标识符替换SUBNET 。

创建端口

  1. 创建指定IP地址的端口:

    $ openstack port create --network net1 --fixed-ip subnet=subnet1,ip-address=192.0.2.40 port1
    +-----------------------+-----------------------------------------+
    | Field                 | Value                                   |
    +-----------------------+-----------------------------------------+
    | admin_state_up        | UP                                      |
    | allowed_address_pairs |                                         |
    | binding_host_id       |                                         |
    | binding_profile       |                                         |
    | binding_vif_details   |                                         |
    | binding_vif_type      | unbound                                 |
    | binding_vnic_type     | normal                                  |
    | created_at            | 2016-12-22T18:54:43Z                    |
    | description           |                                         |
    | device_id             |                                         |
    | device_owner          |                                         |
    | extra_dhcp_opts       |                                         |
    | fixed_ips             | ip_address='192.0.2.40', subnet_id='a   |
    |                       | 394689c-f547-4834-9778-3e0bb22130dc'    |
    | headers               |                                         |
    | id                    | 031ddba8-3e3f-4c3c-ae26-7776905eb24f    |
    | mac_address           | fa:16:3e:df:3d:c7                       |
    | name                  | port1                                   |
    | network_id            | 180620e3-9eae-4ba7-9739-c5847966e1f0    |
    | port_security_enabled | True                                    |
    | project_id            | c961a8f6d3654657885226378ade8220        |
    | revision_number       | 5                                       |
    | security_groups       | 84abb9eb-dc59-40c1-802c-4e173c345b6a    |
    | status                | DOWN                                    |
    | updated_at            | 2016-12-22T18:54:44Z                    |
    +-----------------------+-----------------------------------------+
    

    In the previous command, net1 is the network name, which is a positional argument. --fixed-ip subnet<subnet>,ip-address=192.0.2.40 is an option which specifies the port’s fixed IP address we wanted.

    注解

    当你创建一个端口,你可以指定子网中任何未分配的IP地址,尽管这个地址不再预定义的IP地址池里(由云提供商设定)

  2. 在不指定IP地址的情况下创建一个端口

    $ openstack port create port2 --network net1
    +-----------------------+-----------------------------------------+
    | Field                 | Value                                   |
    +-----------------------+-----------------------------------------+
    | admin_state_up        | UP                                      |
    | allowed_address_pairs |                                         |
    | binding_host_id       |                                         |
    | binding_profile       |                                         |
    | binding_vif_details   |                                         |
    | binding_vif_type      | unbound                                 |
    | binding_vnic_type     | normal                                  |
    | created_at            | 2016-12-22T18:56:06Z                    |
    | description           |                                         |
    | device_id             |                                         |
    | device_owner          |                                         |
    | extra_dhcp_opts       |                                         |
    | fixed_ips             | ip_address='192.0.2.10', subnet_id='a   |
    |                       | 394689c-f547-4834-9778-3e0bb22130dc'    |
    | headers               |                                         |
    | id                    | eac47fcd-07ac-42dd-9993-5b36ac1f201b    |
    | mac_address           | fa:16:3e:96:ae:6e                       |
    | name                  | port2                                   |
    | network_id            | 180620e3-9eae-4ba7-9739-c5847966e1f0    |
    | port_security_enabled | True                                    |
    | project_id            | c961a8f6d3654657885226378ade8220        |
    | revision_number       | 5                                       |
    | security_groups       | 84abb9eb-dc59-40c1-802c-4e173c345b6a    |
    | status                | DOWN                                    |
    | updated_at            | 2016-12-22T18:56:06Z                    |
    +-----------------------+-----------------------------------------+
    

    注解

    Note that the system allocates one IP address if you do not specify an IP address in the openstack port create command.

    注解

    You can specify a MAC address with --mac-address MAC_ADDRESS. If you specify an invalid MAC address, including 00:00:00:00:00:00 or ff:ff:ff:ff:ff:ff, you will get an error.

  3. 具有指定的固定IP地址的查询端口:

    $ neutron port-list --fixed-ips ip_address=192.0.2.2 \
      ip_address=192.0.2.40
    +----------------+------+-------------------+-------------------------------------------------+
    | id             | name | mac_address       | fixed_ips                                       |
    +----------------+------+-------------------+-------------------------------------------------+
    | baf13412-26... |      | fa:16:3e:f6:ec:c7 | {"subnet_id"... ..."ip_address": "192.0.2.2"}   |
    | f7a08fe4-e7... |      | fa:16:3e:97:e0:fc | {"subnet_id"... ..."ip_address": "192.0.2.40"}  |
    +----------------+------+-------------------+-------------------------------------------------+
    
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.