分享

openstack 命令行管理七:外部网络;路由管理 命令总结

xioaxu790 发表于 2014-8-31 16:23:36 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 0 54048
本帖最后由 nettman 于 2014-8-31 23:27 编辑
问题导读
1、如何创建子网和公网?
2、如何使用路由管理的帮助命令?
3、怎样移除路由的默认网关?





创建公网
  1. [root@station140 ~(network_admin)]# neutron net-create --router:external=true  pub1  
  2. Created a new network:  
  3. +---------------------------+--------------------------------------+  
  4. | Field                     | Value                                |  
  5. +---------------------------+--------------------------------------+  
  6. | admin_state_up            | True                                 |  
  7. | id                        | aebe75f0-6013-4a5e-bbd9-cb81e1f017bc |  
  8. | name                      | pub1                                 |  
  9. | provider:network_type     | local                                |  
  10. | provider:physical_network |                                      |  
  11. | provider:segmentation_id  |                                      |  
  12. | router:external           | True                                 |  
  13. | shared                    | False                                |  
  14. | status                    | ACTIVE                               |  
  15. | subnets                   |                                      |  
  16. | tenant_id                 | e3a71a59840c4e88b8740b789c3afb9c     |  
  17. +---------------------------+--------------------------------------+  
  18. 注: 参数 --router:external=true 表示创建的是公网网络
复制代码


查询公网网络信息
  1. [root@station140 ~(keystone_admin)]# nova network-list | grep pub1  
  2. +--------------------------------------+---------+------+  
  3. | ID                                   | Label   | Cidr |  
  4. +--------------------------------------+---------+------+  
  5. | aebe75f0-6013-4a5e-bbd9-cb81e1f017bc | pub1    | None |  
  6. +--------------------------------------+---------+------+
复制代码


############ 注意 ##########
把该 id (aebe75f0-6013-4a5e-bbd9-cb81e1f017bc) 定义到 /etc/neutron/l3_agent.ini
  1. gateway_external_network_id = aebe75f0-6013-4a5e-bbd9-cb81e1f017bc
  2. handle_internal_only_routers = True
  3. external_network_id = aebe75f0-6013-4a5e-bbd9-cb81e1f017bc
  4. external_network_bridge = br-ex
复制代码



重启服务
  1. /etc/init.d/neutron-l3-agent restart  
  2. 注: 上述问题可解决 内部网络 中 ROUTE 显示为 DOWN 状态
  3. ############ 注意 ##########
复制代码


创建子网
  1. neutron subnet-create --name terry_pub_net1 --allocation-pool start=192.168.48.142,end=192.168.48.148 --gateway 192.168.48.1 --dns-nameserver 192.168.86.37 --enable_dhcp=False --ip-version 4  pub1 192.168.48.0/24  
  2. Created a new subnet:  
  3. +------------------+------------------------------------------------------+  
  4. | Field            | Value                                                |  
  5. +------------------+------------------------------------------------------+  
  6. | allocation_pools | {"start": "192.168.48.142", "end": "192.168.48.148"} |  
  7. | cidr             | 192.168.48.0/24                                      |  
  8. | dns_nameservers  | 192.168.86.37                                        |  
  9. | enable_dhcp      | False                                                |  
  10. | gateway_ip       | 192.168.48.1                                         |  
  11. | host_routes      |                                                      |  
  12. | id               | 59cc431b-498e-49a0-bc60-4a8ca1ca6f48                 |  
  13. | ip_version       | 4                                                    |  
  14. | name             | terry_pub_net1                                       |  
  15. | network_id       | aebe75f0-6013-4a5e-bbd9-cb81e1f017bc                 |  
  16. | tenant_id        | e3a71a59840c4e88b8740b789c3afb9c                     |  
  17. +------------------+------------------------------------------------------+
复制代码


删除网络方法
  1. neutron net-delete pub1
复制代码


查询外部网络
  1. [root@station140 ~(network_admin)]# nova floating-ip-pool-list  
  2. +--------+  
  3. | name   |  
  4. +--------+  
  5. | public |  
  6. | pub1   | <- 注: 假如 neutron net-create 不带 --router:external=true 参数, 则代表网络为内部网络  
  7. +--------+  
复制代码




openstack 命令行管理:路由管理
帮助
  1. [root@station140 ~(network_admin)]# neutron help | grep route  
  2.   l3-agent-list-hosting-router   List L3 agents hosting a router.  
  3.   l3-agent-router-add            Add a router to a L3 agent.  
  4.   l3-agent-router-remove         Remove a router from a L3 agent.  
  5.   net-gateway-connect            Add an internal network interface to a router.  
  6.   router-create                  Create a router for a given tenant.  
  7.   router-delete                  Delete a given router.  
  8.   router-gateway-clear           Remove an external network gateway from a router.  
  9.   router-gateway-set             Set the external network gateway for a router.  
  10.   router-interface-add           Add an internal network interface to a router.  
  11.   router-interface-delete        Remove an internal network interface from a router.  
  12.   router-list                    List routers that belong to a given tenant.  
  13.   router-list-on-l3-agent        List the routers on a L3 agent.  
  14.   router-port-list               List ports that belong to a given tenant, with specified router.  
  15.   router-show                    Show information of a given router.  
  16.   router-update                  Update router's information.
复制代码


查询 tenant
  1. [root@station140 ~(network_admin)]#  keystone tenant-list  
  2. +----------------------------------+----------+---------+  
  3. |                id                |   name   | enabled |  
  4. +----------------------------------+----------+---------+  
  5. | 9467f30b8bba4770a06a687e4584636b |  cloud   |   True  |  
  6. +----------------------------------+----------+---------+
复制代码


创建路由连接到外部网络, 这个路由可以与内部网络进行连接
你可以创建过程中指定一个 tenant, 利用参数 --tenant-id 9467f30b8bba4770a06a687e4584636b 进行定义
创建路由
  1. neutron router-create ext-to-int --tenant-id 9467f30b8bba4770a06a687e4584636b  
  2. Created a new router:  
  3. +-----------------------+--------------------------------------+  
  4. | Field                 | Value                                |  
  5. +-----------------------+--------------------------------------+  
  6. | admin_state_up        | True                                 |  
  7. | external_gateway_info |                                      |  
  8. | id                    | b83f43cd-bf8f-42f8-812a-708c2c372820 |  
  9. | name                  | ext-to-int                           |  
  10. | status                | ACTIVE                               |  
  11. | tenant_id             | 9467f30b8bba4770a06a687e4584636b     |  
  12. +-----------------------+--------------------------------------+
复制代码


查询方法
  1. [root@station140 ~(keystone_admin)]# neutron router-list | grep -v router1  
  2. +--------------------------------------+------------+------------------------+  
  3. | id                                   | name       | external_gateway_info  |  
  4. +--------------------------------------+------------+------------------------+  
  5. | b83f43cd-bf8f-42f8-812a-708c2c372820 | ext-to-int | null                   |  
  6. +--------------------------------------+------------+------------------------+
复制代码


查询外部网络
  1. [root@station140 ~(keystone_admin)]# neutron net-list | grep pub1  
  2. +--------------------------------------+---------+------------------------------------------------------+  
  3. | id                                   | name    | subnets                                              |  
  4. +--------------------------------------+---------+------------------------------------------------------+  
  5. | aebe75f0-6013-4a5e-bbd9-cb81e1f017bc | pub1    | 59cc431b-498e-49a0-bc60-4a8ca1ca6f48 192.168.48.0/24 |  
  6. +--------------------------------------+---------+------------------------------------------------------+
复制代码


连接路由到外部网络, 设定外部网络网关
  1. # neutron router-gateway-set b83f43cd-bf8f-42f8-812a-708c2c372820 aebe75f0-6013-4a5e-bbd9-cb81e1f017bc  
  2.   
  3. [root@station140 ~(keystone_admin)]# neutron router-list | grep -v router1  
  4. +--------------------------------------+------------+-----------------------------------------------------------------------------+  
  5. | id                                   | name       | external_gateway_info                                                       |  
  6. +--------------------------------------+------------+-----------------------------------------------------------------------------+  
  7. | b83f43cd-bf8f-42f8-812a-708c2c372820 | ext-to-int | {"network_id": "aebe75f0-6013-4a5e-bbd9-cb81e1f017bc", "enable_snat": true} |  
  8. +--------------------------------------+------------+-----------------------------------------------------------------------------+  
复制代码



列出子网信息
  1. [root@station140 ~(keystone_admin)]# neutron subnet-list | grep terry  
  2. +--------------------------------------+----------------+-----------------+------------------------------------------------------+  
  3. | id                                   | name           | cidr            | allocation_pools                                     |  
  4. +--------------------------------------+----------------+-----------------+------------------------------------------------------+  
  5. | 3066c397-bccf-4473-8a94-72b09a97a70a | terry_pri_net1 | 10.0.0.0/8      | {"start": "10.0.0.50", "end": "10.0.0.100"}          |  
  6. | 59cc431b-498e-49a0-bc60-4a8ca1ca6f48 | terry_pub_net1 | 192.168.48.0/24 | {"start": "192.168.48.142", "end": "192.168.48.148"} |  
  7. +--------------------------------------+----------------+-----------------+------------------------------------------------------+
复制代码



创建内部网络路由接口
  1. [root@station140 ~(network_admin)]# neutron router-interface-add b83f43cd-bf8f-42f8-812a-708c2c372820 3066c397-bccf-4473-8a94-72b09a97a70a  
  2. Added interface c9566299-44ed-4924-b845-4fc48bd4de98bbfe84a2-508e-47a1-a664-27b2e8121893 to router b83f43cd-bf8f-42f8-812a-708c2c372820.
复制代码


显示路由信息
  1. [root@station140 ~(keystone_admin)]# neutron router-show b83f43cd-bf8f-42f8-812a-708c2c372820  
  2. +-----------------------+-----------------------------------------------------------------------------+  
  3. | Field                 | Value                                                                       |  
  4. +-----------------------+-----------------------------------------------------------------------------+  
  5. | admin_state_up        | True                                                                        |  
  6. | external_gateway_info | {"network_id": "aebe75f0-6013-4a5e-bbd9-cb81e1f017bc", "enable_snat": true} |  
  7. | id                    | b83f43cd-bf8f-42f8-812a-708c2c372820                                        |  
  8. | name                  | ext-to-int                                                                  |  
  9. | routes                |                                                                             |  
  10. | status                | ACTIVE                                                                      |  
  11. | tenant_id             | 9467f30b8bba4770a06a687e4584636b                                            |  
  12. +-----------------------+-----------------------------------------------------------------------------+  
复制代码


移除路由接口 (interface)
  1. [root@station140 ~(keystone_admin)]# neutron router-interface-delete b83f43cd-bf8f-42f8-812a-708c2c372820 3066c397-bccf-4473-8a94-72b09a97a70a  
  2. Removed interface from router b83f43cd-bf8f-42f8-812a-708c2c372820
复制代码


移除路由的默认网关
查询
  1. [root@station140 ~(keystone_admin)]# neutron router-list | grep network | grep ext-to-int  
  2. +--------------------------------------+------------+-----------------------------------------------------------------------------+  
  3. | id                                   | name       | external_gateway_info                                                       |  
  4. +--------------------------------------+------------+-----------------------------------------------------------------------------+  
  5. | b83f43cd-bf8f-42f8-812a-708c2c372820 | ext-to-int | {"network_id": "aebe75f0-6013-4a5e-bbd9-cb81e1f017bc", "enable_snat": true} |  
  6. +--------------------------------------+------------+-----------------------------------------------------------------------------+
复制代码

当 external_gateway_info 则表示具有默认网关

删除网关接口
  1. [root@station140 ~(keystone_admin)]# neutron router-gateway-clear b83f43cd-bf8f-42f8-812a-708c2c372820  
  2. Removed gateway from router b83f43cd-bf8f-42f8-812a-708c2c372820
复制代码


下面显示为不具备网关的路由
  1. [root@station140 ~(keystone_admin)]# neutron router-list | grep ext-to-int  
  2. +--------------------------------------+------------+-----------------------+  
  3. | id                                   | name       | external_gateway_info |  
  4. +--------------------------------------+------------+-----------------------+  
  5. | b83f43cd-bf8f-42f8-812a-708c2c372820 | ext-to-int | null          |  
  6. +--------------------------------------+------------+-----------------------+
复制代码


删除路由
  1. [root@station140 ~(keystone_admin)]# neutron router-delete b83f43cd-bf8f-42f8-812a-708c2c372820  
  2. Deleted router: b83f43cd-bf8f-42f8-812a-708c2c372820
复制代码


上一篇:
openstack 命令行管理六:安全组管理;内部网络管理 命令总结


下一篇
openstack 命令行管理八:浮动 IP 管理;网络测试 命令总结


没找到任何评论,期待你打破沉寂

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条