Openstack网络配置--命令行篇

来源:互联网 发布:ubuntu ntp服务器设置 编辑:程序博客网 时间:2024/06/06 13:02

前面讲过网络配置horizon篇,本文讲使用命令行配置openstack网络。


1、首先source openers.sh脚本,该脚本中是一些环境变量:


运行该脚本,即可通过命令行来管理云资源了:

[root@cloud~]#source openrc.sh 


2、创建public网络:

[root@cloud ~]#openstack network create --external --provider-physical-network physnet1--provider-network-type flat public

+---------------------------+--------------------------------------+

| Field                    | Value                               |

+---------------------------+--------------------------------------+

| admin_state_up           | UP                                 |

| availability_zone_hints   |                                     |

| availability_zones        |                                     |

| created_at               |2017-06-12T09:48:49Z                 |

| description              |                                    |

| dns_domain               | None                                |

| id                       | fcc2d335-87cd-463f-ac1d-4b8c7c054641 |

| ipv4_address_scope        | None                                |

| ipv6_address_scope        | None                                |

| is_default               | False                               |

| mtu                      | 1500                                |

| name                     | public                              |

| port_security_enabled     | False                               |

| project_id               |4e79773819ff4f779802bceb4e7bf58a     |

| provider:network_type     | flat                                |

| provider:physical_network |physnet1                           |

| provider:segmentation_id  | None                                |

| qos_policy_id            | None                                |

| revision_number          | 3                                  |

| router:external          | External                            |

| segments                 |None                               |

| shared                   | False                               |

| status                   | ACTIVE                              |

| subnets                  |                                    |

| updated_at               |2017-06-12T09:48:49Z                 |

+---------------------------+--------------------------------------+

给public网络添加子网:

[root@cloud ~]#openstack subnet create --no-dhcp --allocation-poolstart=192.168.60.30,end=192.168.60.90 --network public --subnet-range192.168.60.0/24 --gateway 192.168.60.247 public-subnet

+-------------------+--------------------------------------+

| Field            | Value                               |

+-------------------+--------------------------------------+

| allocation_pools  | 192.168.60.30-192.168.60.90         |

| cidr             | 192.168.60.0/24                     |

| created_at        | 2017-06-12T09:50:56Z                |

| description       |                                     |

| dns_nameservers   |                                     |

| enable_dhcp       | False                               |

| gateway_ip        | 192.168.60.247                      |

| host_routes       |                                     |

| id               |1022cf1b-e6d9-4373-9e38-7e3b4ba1b3c4 |

| ip_version        | 4                                   |

| ipv6_address_mode | None                                |

| ipv6_ra_mode      | None                                |

| name             | public-subnet                       |

| network_id        | fcc2d335-87cd-463f-ac1d-4b8c7c054641 |

| project_id        | 4e79773819ff4f779802bceb4e7bf58a     |

| revision_number   | 2                                   |

| segment_id        | None                                |

| service_types     |                                     |

| subnetpool_id     | None                                |

| updated_at        | 2017-06-12T09:50:56Z                |

+-------------------+--------------------------------------+


3、创建私有网络:

[root@cloud ~]#openstack network create --provider-network-type vxlan demo-net

+---------------------------+--------------------------------------+

| Field                    | Value                               |

+---------------------------+--------------------------------------+

| admin_state_up           | UP                                 |

| availability_zone_hints   |                                     |

| availability_zones        |                                     |

| created_at               |2017-06-12T09:52:07Z                 |

| description              |                                    |

| dns_domain               | None                                |

| id                       | 51ec6ecc-896f-495b-bb97-e103d3d49a01 |

| ipv4_address_scope        | None                                |

| ipv6_address_scope        | None                                |

| is_default               | None                                |

| mtu                      | 1450                                |

| name                     | demo-net                            |

| port_security_enabled     | False                               |

| project_id               |4e79773819ff4f779802bceb4e7bf58a     |

| provider:network_type     | vxlan                               |

| provider:physical_network | None                                |

| provider:segmentation_id  | 79                                  |

| qos_policy_id            | None                                |

| revision_number          | 2                                  |

| router:external          | Internal                            |

| segments                 |None                               |

| shared                   | False                               |

| status                   | ACTIVE                              |

| subnets                  |                                    |

| updated_at               |2017-06-12T09:52:07Z                 |

+---------------------------+--------------------------------------+

给私有网络添加子网:

[root@cloud ~]#openstack subnet create --subnet-range 10.56.1.0/24 --network demo-net--gateway 10.56.1.1 --dns-nameserver 8.8.8.8 demo-subnet

+-------------------+--------------------------------------+

| Field            | Value                               |

+-------------------+--------------------------------------+

| allocation_pools  | 10.56.1.2-10.56.1.254               |

| cidr             | 10.56.1.0/24                        |

| created_at        | 2017-06-12T09:52:25Z                |

| description       |                                     |

| dns_nameservers   | 8.8.8.8                             |

| enable_dhcp       | True                                |

| gateway_ip        | 10.56.1.1                           |

| host_routes       |                                     |

| id               |d9798602-0e59-4206-8a53-c8a948fd020b |

| ip_version        | 4                                   |

| ipv6_address_mode | None                                |

| ipv6_ra_mode      | None                                |

| name             | demo-subnet                         |

| network_id        | 51ec6ecc-896f-495b-bb97-e103d3d49a01 |

| project_id        | 4e79773819ff4f779802bceb4e7bf58a     |

| revision_number   | 2                                   |

| segment_id        | None                                |

| service_types     |                                     |

| subnetpool_id     | None                                |

| updated_at        | 2017-06-12T09:52:25Z                |

+-------------------+--------------------------------------+


4、给外网和私网之间添加路由:

[root@cloud ~]#openstack router create demo-router

+-------------------------+--------------------------------------+

| Field                  | Value                               |

+-------------------------+--------------------------------------+

| admin_state_up         | UP                                 |

| availability_zone_hints |                                    |

| availability_zones      |                                     |

| created_at             |2017-06-12T09:52:38Z                 |

| description            |                                    |

| distributed            | False                               |

| external_gateway_info   | None                                |

| flavor_id              | None                                |

| ha                     | False                               |

| id                     | 7f7a7d73-d640-4c40-b41c-c0a7adc2e018 |

| name                   | demo-router                         |

| project_id             |4e79773819ff4f779802bceb4e7bf58a     |

| revision_number         | None                                |

| routes                 |                                    |

| status                 |ACTIVE                             |

| updated_at             |2017-06-12T09:52:38Z                 |

+-------------------------+--------------------------------------+

[root@cloud ~]#openstack router add subnet demo-router demo-subnet

[root@cloud ~]#openstack router set --external-gateway public demo-router


5、通过下面的命令可以查询刚刚所建的网络信息:

[root@cloud ~]#neutron net-list

neutron CLI is deprecated and willbe removed in the future. Use openstack CLI instead.

+---------------------+----------+---------------------+-----------------------+

| id                          |name    | tenant_id          | subnets             |

+---------------------+----------+---------------------+-----------------------+

| 51ec6ecc-896f-495b- | demo-net |4e79773819ff4f77980 | d9798602-0e59-4206-8a |

| bb97-e103d3d49a01   |                | 2bceb4e7bf58a       |53-c8a948fd020b       |

|                                     |                 |                                | 10.56.1.0/24          |

| fcc2d335-87cd-463f- | public   | 4e79773819ff4f77980 | 1022cf1b-e6d9-4373-9e |

| ac1d-4b8c7c054641   |             | 2bceb4e7bf58a       |38-7e3b4ba1b3c4       |

|                                    |             |                                  | 192.168.60.0/24       |

+---------------------+----------+---------------------+-----------------------+


6、登到dashboard上面去看network topology:


至此,使用命令行创建简单的网络拓扑结束。

原创粉丝点击