分享

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

xioaxu790 发表于 2014-8-30 18:11:52 [显示全部楼层] 回帖奖励 阅读模式 关闭右栏 2 57343
本帖最后由 nettman 于 2014-8-31 23:29 编辑
问题导读
1、如何创建和列出自定义安全组?
2、如何显示网络 extension 详细信息?
3、如何使用网络管理帮助?





参考官方资料
You must modify the rules for the default security group because users cannot access instances that use the default group from   
any IP address outside the cloud.  

You can modify the rules in a security group to allow access to instances through different ports and protocols. For example,   
you can modify rules to allow access to instances through SSH, to ping them, or to allow UDP traffic – for example, for a DNS   
server running on an instance. You specify the following parameters for rules:  

Source of traffic. Enable traffic to instances from either IP addresses inside the cloud from other group members or from all IP addresses.  

Protocol. Choose TCP for SSH, ICMP for pings, or UDP.  

Destination port on virtual machine. Defines a port range. To open a single port only, enter the same value twice. ICMP does not support ports: Enter values to define the codes and types of ICMP traffic to be allowed.  

Rules are automatically enforced as soon as you create or modify them.  

注: 已通过测试, 修改默认 secgroup 或自定义 secgroup 都可以完成数据访问测试
帮助
  1. [root@station140 ~(keystone_admin)]# nova help | grep secgroup  
  2.     add-secgroup        Add a Security Group to a server.  
  3.     list-secgroup       List Security Group(s) of a server.  
  4.     remove-secgroup     Remove a Security Group from a server.  
  5.     secgroup-add-group-rule  
  6.     secgroup-add-rule   Add a rule to a security group.  
  7.     secgroup-create     Create a security group.  
  8.     secgroup-delete     Delete a security group.  
  9.     secgroup-delete-group-rule  
  10.     secgroup-delete-rule  
  11.     secgroup-list       List security groups for the current tenant.  
  12.     secgroup-list-rules  
  13.     secgroup-update     Update a security group.  
复制代码


创建自定义安全组
  1. [root@station140 ~(keystone_admin)]# nova secgroup-create terry "allow ping and ssh"  
  2. +--------------------------------------+-------+--------------------+  
  3. | Id                                   | Name  | Description        |  
  4. +--------------------------------------+-------+--------------------+  
  5. | 6966a8e4-0980-40ad-a409-baac65b60287 | terry | allow ping and ssh |  
  6. +--------------------------------------+-------+--------------------+  
复制代码


列出当前所有安全组
  1. [root@station140 ~(keystone_admin)]# nova  secgroup-list  
  2. +--------------------------------------+---------+--------------------+  
  3. | Id                                   | Name    | Description        |  
  4. +--------------------------------------+---------+--------------------+  
  5. | 91a191a6-b89e-4f87-99c0-0fb985985978 | default | default            |  
  6. | 6966a8e4-0980-40ad-a409-baac65b60287 | terry   | allow ping and ssh |  
  7. +--------------------------------------+---------+--------------------+  
复制代码


列出某个组中的安全规则
  1. [root@station140 ~(keystone_admin)]# nova  secgroup-list-rules default  
  2. +-------------+-----------+---------+----------+--------------+  
  3. | IP Protocol | From Port | To Port | IP Range | Source Group |  
  4. +-------------+-----------+---------+----------+--------------+  
  5. |             |           |         |          | default      |  
  6. |             |           |         |          | default      |  
  7. +-------------+-----------+---------+----------+--------------+  
复制代码


增加规则方法 (允许 ping)
  1. [root@station140 ~(keystone_admin)]# nova secgroup-add-rule terry icmp -1 -1 0.0.0.0/0  
  2. +-------------+-----------+---------+-----------+--------------+  
  3. | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  4. +-------------+-----------+---------+-----------+--------------+  
  5. | icmp        | -1        | -1      | 0.0.0.0/0 |              |  
  6. +-------------+-----------+---------+-----------+--------------+  
复制代码


增加规则方法 (允许 ssh)
  1. [root@station140 ~(keystone_admin)]# nova secgroup-add-rule terry tcp  22 22 0.0.0.0/0  
  2. +-------------+-----------+---------+-----------+--------------+  
  3. | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  4. +-------------+-----------+---------+-----------+--------------+  
  5. | tcp         | 22        | 22      | 0.0.0.0/0 |              |  
  6. +-------------+-----------+---------+-----------+--------------+  
复制代码


增加规则方法 (允许 dns 外部访问)
  1. [root@station140 ~(keystone_admin)]# nova secgroup-add-rule terry udp 53 53 0.0.0.0/0  
  2. +-------------+-----------+---------+-----------+--------------+  
  3. | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  4. +-------------+-----------+---------+-----------+--------------+  
  5. | udp         | 53        | 53      | 0.0.0.0/0 |              |  
  6. +-------------+-----------+---------+-----------+--------------+
复制代码


列出自定义组规则
  1. [root@station140 ~(keystone_admin)]# nova secgroup-list-rules terry  
  2. +-------------+-----------+---------+-----------+--------------+  
  3. | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  4. +-------------+-----------+---------+-----------+--------------+  
  5. | tcp         | 22        | 22      | 0.0.0.0/0 |              |  
  6. | udp         | 53        | 53      | 0.0.0.0/0 |              |  
  7. | icmp        | -1        | -1      | 0.0.0.0/0 |              |  
  8. +-------------+-----------+---------+-----------+--------------+
复制代码


尝试修改 default secgroup
列出 default secgroup 规则
  1. [root@station140 ~(keystone_admin)]# nova secgroup-list-rules default  
  2. +-------------+-----------+---------+----------+--------------+  
  3. | IP Protocol | From Port | To Port | IP Range | Source Group |  
  4. +-------------+-----------+---------+----------+--------------+  
  5. |             |           |         |          | default      |  
  6. |             |           |         |          | default      |  
  7. +-------------+-----------+---------+----------+--------------+
复制代码


添加规则 (允许 ping)
  1. [root@station140 ~(keystone_admin)]# nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0  
  2. +-------------+-----------+---------+-----------+--------------+  
  3. | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  4. +-------------+-----------+---------+-----------+--------------+  
  5. | icmp        | -1        | -1      | 0.0.0.0/0 |              |  
  6. +-------------+-----------+---------+-----------+--------------+  
复制代码


添加规则 (允许 ssh)
  1. [root@station140 ~(keystone_admin)]# nova secgroup-add-rule default tcp  22 22 0.0.0.0/0  
  2. +-------------+-----------+---------+-----------+--------------+  
  3. | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  4. +-------------+-----------+---------+-----------+--------------+  
  5. | tcp         | 22        | 22      | 0.0.0.0/0 |              |  
  6. +-------------+-----------+---------+-----------+--------------+
复制代码


添加规则 (允许 dns外部访问)
  1. [root@station140 ~(keystone_admin)]# nova secgroup-add-rule default udp 53 53 0.0.0.0/0  
  2. +-------------+-----------+---------+-----------+--------------+  
  3. | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  4. +-------------+-----------+---------+-----------+--------------+  
  5. | udp         | 53        | 53      | 0.0.0.0/0 |              |  
  6. +-------------+-----------+---------+-----------+--------------+  
复制代码


列出默认组规则
  1. [root@station140 ~(keystone_admin)]# nova secgroup-list-rules default  
  2. +-------------+-----------+---------+-----------+--------------+  
  3. | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  4. +-------------+-----------+---------+-----------+--------------+  
  5. |             |           |         |           | default      |  
  6. | icmp        | -1        | -1      | 0.0.0.0/0 |              |  
  7. | tcp         | 22        | 22      | 0.0.0.0/0 |              |  
  8. |             |           |         |           | default      |  
  9. | udp         | 53        | 53      | 0.0.0.0/0 |              |  
  10. +-------------+-----------+---------+-----------+--------------+
复制代码


删除某个实例, 使用中的规则
  1. nova remove-secgroup terry_instance1 terry
复制代码


注: 在虚拟机启动后, 无法在增加其他规则



openstack 命令行管理:内部网络[instance专用]管理
ip 帮助
  1. [root@station140 ~(keystone_admin)]# nova help | grep ip  
  2.     add-fixed-ip        Add new IP address on a network to server.  
  3.     add-floating-ip     Add a floating IP address to a server.  
  4.     cloudpipe-configure  
  5.                         Update the VPN IP/port of a cloudpipe instance.  
  6.     cloudpipe-create    Create a cloudpipe instance for the given project.  
  7.     cloudpipe-list      Print a list of all cloudpipe instances.  
  8.     dns-create          Create a DNS entry for domain, name and ip.  
  9.     dns-list            List current DNS entries for domain and ip or domain  
  10.     fixed-ip-get        Retrieve info on a fixed ip.  
  11.     fixed-ip-reserve    Reserve a fixed IP.  
  12.     fixed-ip-unreserve  Unreserve a fixed IP.  
  13.     floating-ip-bulk-create  
  14.                         Bulk create floating ips by range.  
  15.     floating-ip-bulk-delete  
  16.                         Bulk delete floating ips by range.  
  17.     floating-ip-bulk-list  
  18.                         List all floating ips.  
  19.     floating-ip-create  Allocate a floating IP for the current tenant.  
  20.     floating-ip-delete  De-allocate a floating IP.  
  21.     floating-ip-list    List floating ips for this tenant.  
  22.     floating-ip-pool-list  
  23.                         List all floating ip pools.  
  24.     remove-fixed-ip     Remove an IP address from a server.  
  25.     remove-floating-ip  Remove a floating IP address from a server.  
复制代码


网络管理帮助
  1. [root@station140 ~(keystone_admin)]# nova help | grep network  
  2.     interface-attach    Attach a network interface to an instance.  
  3.     interface-detach    Detach a network interface from an instance.  
  4.     network-associate-host  
  5.                         Associate host with network.  
  6.     network-associate-project  
  7.                         Associate project with network.  
  8.     network-create      Create a network.  
  9.     network-disassociate  
  10.                         network.  
  11.     network-list        Print a list of available networks.  
  12.     network-show        Show details about the given network.  
  13.     reset-network       Reset network of an instance.  
  14.                         Add a network interface to a baremetal node.  
  15.                         List network interfaces associated with a baremetal  
  16.                         Remove a network interface from a baremetal node.  
  17.     net                 Show a network  
  18.     net-create          Create a network  
  19.     net-delete          Delete a network  
  20.     net-list            List networks  
复制代码


显示当前 openstack 网络方法
  1. [root@station140 ~(keystone_admin)]# nova network-list  
  2. +--------------------------------------+---------+------+  
  3. | ID                                   | Label   | Cidr |  
  4. +--------------------------------------+---------+------+  
  5. | 68a1d874-e7bd-42e2-9f86-8eb0b0b4b8fd | public  | None |  
  6. | e8e14001-44d9-4ab1-a462-ea621b8a4746 | private | None |  
  7. +--------------------------------------+---------+------+  
复制代码


参考 openstack 官方文档, 在某些旧版本中, 需要利用下面方法创建网络, 当前 H 版本可以不使用下面变量
  1. export OS_USERNAME=admin  
  2. export OS_PASSWORD=password  
  3. export OS_TENANT_NAME=admin  
  4. export OS_AUTH_URL=http://localhost:5000/v2.0
复制代码


另外一种列出网络方法
  1. [root@station140 ~(network_admin)]# neutron net-list  
  2. +--------------------------------------+---------+------------------------------------------------------+  
  3. | id                                   | name    | subnets                                              |  
  4. +--------------------------------------+---------+------------------------------------------------------+  
  5. | 68a1d874-e7bd-42e2-9f86-8eb0b0b4b8fd | public  | ce0a4a92-5c23-4557-ad67-97560ab5afa1 172.24.4.224/28 |  
  6. | e8e14001-44d9-4ab1-a462-ea621b8a4746 | private | 79fdeabd-7f8a-4619-a17d-87864ccdfa80 10.0.0.0/24     |  
  7. +--------------------------------------+---------+------------------------------------------------------+
复制代码


显示某个网络详细信息
  1. [root@station140 ~(network_admin)]# neutron net-show public  
  2. +---------------------------+--------------------------------------+  
  3. | Field                     | Value                                |  
  4. +---------------------------+--------------------------------------+  
  5. | admin_state_up            | True                                 |  
  6. | id                        | 68a1d874-e7bd-42e2-9f86-8eb0b0b4b8fd |  
  7. | name                      | public                               |  
  8. | provider:network_type     | local                                |  
  9. | provider:physical_network |                                      |  
  10. | provider:segmentation_id  |                                      |  
  11. | router:external           | True                                 |  
  12. | shared                    | False                                |  
  13. | status                    | ACTIVE                               |  
  14. | subnets                   | ce0a4a92-5c23-4557-ad67-97560ab5afa1 |  
  15. | tenant_id                 | e3a71a59840c4e88b8740b789c3afb9c     |  
  16. +---------------------------+--------------------------------------+  
复制代码


显示网络 extension 详细信息
  1. [root@station140 ~(keystone_admin)]# neutron ext-list  
  2. +-----------------------+-----------------------------------------------+  
  3. | alias                 | name                                          |  
  4. +-----------------------+-----------------------------------------------+  
  5. | ext-gw-mode           | Neutron L3 Configurable external gateway mode |  
  6. | security-group        | security-group                                |  
  7. | l3_agent_scheduler    | L3 Agent Scheduler                            |  
  8. | provider              | Provider Network                              |  
  9. | binding               | Port Binding                                  |  
  10. | quotas                | Quota management support                      |  
  11. | agent                 | agent                                         |  
  12. | dhcp_agent_scheduler  | DHCP Agent Scheduler                          |  
  13. | external-net          | Neutron external network                      |  
  14. | router                | Neutron L3 Router                             |  
  15. | allowed-address-pairs | Allowed Address Pairs                         |  
  16. | extra_dhcp_opt        | Neutron Extra DHCP opts                       |  
  17. | extraroute            | Neutron Extra Route                           |  
  18. +-----------------------+-----------------------------------------------+  
复制代码


创建私有网络
  1. [root@station140 ~(network_admin)]# neutron net-create net1  
  2. Created a new network:  
  3. +---------------------------+--------------------------------------+  
  4. | Field                     | Value                                |  
  5. +---------------------------+--------------------------------------+  
  6. | admin_state_up            | True                                 |  
  7. | id                        | d0e3f988-d62f-4f95-ab21-b73f4dae326b |  
  8. | name                      | net1                                 |  
  9. | provider:network_type     | local                                |  
  10. | provider:physical_network |                                      |  
  11. | provider:segmentation_id  |                                      |  
  12. | shared                    | False                                |  
  13. | status                    | ACTIVE                               |  
  14. | subnets                   |                                      |  
  15. | tenant_id                 | e3a71a59840c4e88b8740b789c3afb9c     |  
  16. +---------------------------+--------------------------------------+  
复制代码


显示 net1 网络详细信息
  1. [root@station140 ~(keystone_admin)]# neutron net-show net1  
  2. +---------------------------+--------------------------------------+  
  3. | Field                     | Value                                |  
  4. +---------------------------+--------------------------------------+  
  5. | admin_state_up            | True                                 |  
  6. | id                        | d0e3f988-d62f-4f95-ab21-b73f4dae326b |  
  7. | name                      | net1                                 |  
  8. | provider:network_type     | local                                |  
  9. | provider:physical_network |                                      |  
  10. | provider:segmentation_id  |                                      |  
  11. | router:external           | False                                |  
  12. | shared                    | False                                |  
  13. | status                    | ACTIVE                               |  
  14. | subnets                   |                                      |  
  15. | tenant_id                 | e3a71a59840c4e88b8740b789c3afb9c     |  
  16. +---------------------------+--------------------------------------+  
复制代码


创建私网络 net1 的子网
  1. [root@station140 ~(network_admin)]# neutron subnet-create --name terry_pri_net1 --allocation-pool start=10.0.0.50,end=10.0.0.100 --no-gateway --ip-version 4  net1 10.0.0.0/24  
  2. Created a new subnet:  
  3. +------------------+---------------------------------------------+  
  4. | Field            | Value                                       |  
  5. +------------------+---------------------------------------------+  
  6. | allocation_pools | {"start": "10.0.0.50", "end": "10.0.0.100"} |  
  7. | cidr             | 10.0.0.0/24                                  |  
  8. | dns_nameservers  |                                             |  
  9. | enable_dhcp      | True                                        |  
  10. | gateway_ip       |                                             |  
  11. | host_routes      |                                             |  
  12. | id               | 3066c397-bccf-4473-8a94-72b09a97a70a        |  
  13. | ip_version       | 4                                           |  
  14. | name             | terry_pri_net1                              |  
  15. | network_id       | d0e3f988-d62f-4f95-ab21-b73f4dae326b        |  
  16. | tenant_id        | e3a71a59840c4e88b8740b789c3afb9c            |  
  17. +------------------+---------------------------------------------+  
复制代码


显示 net1 网络详细信息
  1. [root@station140 ~(keystone_admin)]# neutron net-show net1  
  2. +---------------------------+--------------------------------------+  
  3. | Field                     | Value                                |  
  4. +---------------------------+--------------------------------------+  
  5. | admin_state_up            | True                                 |  
  6. | id                        | d0e3f988-d62f-4f95-ab21-b73f4dae326b |  
  7. | name                      | net1                                 |  
  8. | provider:network_type     | local                                |  
  9. | provider:physical_network |                                      |  
  10. | provider:segmentation_id  |                                      |  
  11. | router:external           | False                                |  
  12. | shared                    | False                                |  
  13. | status                    | ACTIVE                               |  
  14. | subnets                   | 3066c397-bccf-4473-8a94-72b09a97a70a |  
  15. | tenant_id                 | e3a71a59840c4e88b8740b789c3afb9c     |  
  16. +---------------------------+--------------------------------------+  
复制代码


注意 net1 中的 subnets values 部分 3066c397-bccf-4473-8a94-72b09a97a70a 显示为 terry_pri_net1 中的 ID 值


上一篇:
openstack 命令行管理五:flavor管理;密钥管理 命令总结

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

已有(2)人评论

跳转到指定楼层
anyhuayong 发表于 2014-8-31 12:26:53
好东西,分享了
回复

使用道具 举报

Afuge 发表于 2015-6-16 14:06:03
学习了,谢谢分享!
回复

使用道具 举报

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

本版积分规则

关闭

推荐上一条 /2 下一条