设为首页 收藏本站
查看: 3511|回复: 0

[经验分享] openstack安全组规则

[复制链接]

尚未签到

发表于 2016-1-9 08:22:04 | 显示全部楼层 |阅读模式
  http://www.aboutyun.com/thread-8964-1-1.html
  
  
  
  参考官方资料
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 都可以完成数据访问测试
帮助

  • [iyunv@station140 ~(keystone_admin)]# nova help | grep secgroup  
  •     add-secgroup        Add a Security Group to a server.  
  •     list-secgroup       List Security Group(s) of a server.  
  •     remove-secgroup     Remove a Security Group from a server.  
  •     secgroup-add-group-rule  
  •     secgroup-add-rule   Add a rule to a security group.  
  •     secgroup-create     Create a security group.  
  •     secgroup-delete     Delete a security group.  
  •     secgroup-delete-group-rule  
  •     secgroup-delete-rule  
  •     secgroup-list       List security groups for the current tenant.  
  •     secgroup-list-rules  
  •     secgroup-update     Update a security group.  

[color=#336699 !important]复制代码
  

创建自定义安全组

  • [iyunv@station140 ~(keystone_admin)]# nova secgroup-create terry "allow ping and ssh"  
  • +--------------------------------------+-------+--------------------+  
  • | Id                                   | Name  | Description        |  
  • +--------------------------------------+-------+--------------------+  
  • | 6966a8e4-0980-40ad-a409-baac65b60287 | terry | allow ping and ssh |  
  • +--------------------------------------+-------+--------------------+  

[color=#336699 !important]复制代码
  

列出当前所有安全组

  • [iyunv@station140 ~(keystone_admin)]# nova  secgroup-list  
  • +--------------------------------------+---------+--------------------+  
  • | Id                                   | Name    | Description        |  
  • +--------------------------------------+---------+--------------------+  
  • | 91a191a6-b89e-4f87-99c0-0fb985985978 | default | default            |  
  • | 6966a8e4-0980-40ad-a409-baac65b60287 | terry   | allow ping and ssh |  
  • +--------------------------------------+---------+--------------------+  

[color=#336699 !important]复制代码
  

列出某个组中的安全规则

  • [iyunv@station140 ~(keystone_admin)]# nova  secgroup-list-rules default  
  • +-------------+-----------+---------+----------+--------------+  
  • | IP Protocol | From Port | To Port | IP Range | Source Group |  
  • +-------------+-----------+---------+----------+--------------+  
  • |             |           |         |          | default      |  
  • |             |           |         |          | default      |  
  • +-------------+-----------+---------+----------+--------------+  

[color=#336699 !important]复制代码
  

增加规则方法 (允许 ping)

  • [iyunv@station140 ~(keystone_admin)]# nova secgroup-add-rule terry icmp -1 -1 0.0.0.0/0  
  • +-------------+-----------+---------+-----------+--------------+  
  • | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  • +-------------+-----------+---------+-----------+--------------+  
  • | icmp        | -1        | -1      | 0.0.0.0/0 |              |  
  • +-------------+-----------+---------+-----------+--------------+  

[color=#336699 !important]复制代码
  

增加规则方法 (允许 ssh)

  • [iyunv@station140 ~(keystone_admin)]# nova secgroup-add-rule terry tcp  22 22 0.0.0.0/0  
  • +-------------+-----------+---------+-----------+--------------+  
  • | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  • +-------------+-----------+---------+-----------+--------------+  
  • | tcp         | 22        | 22      | 0.0.0.0/0 |              |  
  • +-------------+-----------+---------+-----------+--------------+  

[color=#336699 !important]复制代码
  

增加规则方法 (允许 dns 外部访问)

  • [iyunv@station140 ~(keystone_admin)]# nova secgroup-add-rule terry udp 53 53 0.0.0.0/0  
  • +-------------+-----------+---------+-----------+--------------+  
  • | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  • +-------------+-----------+---------+-----------+--------------+  
  • | udp         | 53        | 53      | 0.0.0.0/0 |              |  
  • +-------------+-----------+---------+-----------+--------------+

[color=#336699 !important]复制代码
  

列出自定义组规则

  • [iyunv@station140 ~(keystone_admin)]# nova secgroup-list-rules terry  
  • +-------------+-----------+---------+-----------+--------------+  
  • | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  • +-------------+-----------+---------+-----------+--------------+  
  • | tcp         | 22        | 22      | 0.0.0.0/0 |              |  
  • | udp         | 53        | 53      | 0.0.0.0/0 |              |  
  • | icmp        | -1        | -1      | 0.0.0.0/0 |              |  
  • +-------------+-----------+---------+-----------+--------------+

[color=#336699 !important]复制代码
  

尝试修改 default secgroup
列出 default secgroup 规则

  • [iyunv@station140 ~(keystone_admin)]# nova secgroup-list-rules default  
  • +-------------+-----------+---------+----------+--------------+  
  • | IP Protocol | From Port | To Port | IP Range | Source Group |  
  • +-------------+-----------+---------+----------+--------------+  
  • |             |           |         |          | default      |  
  • |             |           |         |          | default      |  
  • +-------------+-----------+---------+----------+--------------+

[color=#336699 !important]复制代码
  

添加规则 (允许 ping)

  • [iyunv@station140 ~(keystone_admin)]# nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0  
  • +-------------+-----------+---------+-----------+--------------+  
  • | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  • +-------------+-----------+---------+-----------+--------------+  
  • | icmp        | -1        | -1      | 0.0.0.0/0 |              |  
  • +-------------+-----------+---------+-----------+--------------+  

[color=#336699 !important]复制代码
  

添加规则 (允许 ssh)

  • [iyunv@station140 ~(keystone_admin)]# nova secgroup-add-rule default tcp  22 22 0.0.0.0/0  
  • +-------------+-----------+---------+-----------+--------------+  
  • | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  • +-------------+-----------+---------+-----------+--------------+  
  • | tcp         | 22        | 22      | 0.0.0.0/0 |              |  
  • +-------------+-----------+---------+-----------+--------------+

[color=#336699 !important]复制代码
  

添加规则 (允许 dns外部访问)

  • [iyunv@station140 ~(keystone_admin)]# nova secgroup-add-rule default udp 53 53 0.0.0.0/0  
  • +-------------+-----------+---------+-----------+--------------+  
  • | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  • +-------------+-----------+---------+-----------+--------------+  
  • | udp         | 53        | 53      | 0.0.0.0/0 |              |  
  • +-------------+-----------+---------+-----------+--------------+  

[color=#336699 !important]复制代码
  

列出默认组规则

  • [iyunv@station140 ~(keystone_admin)]# nova secgroup-list-rules default  
  • +-------------+-----------+---------+-----------+--------------+  
  • | IP Protocol | From Port | To Port | IP Range  | Source Group |  
  • +-------------+-----------+---------+-----------+--------------+  
  • |             |           |         |           | default      |  
  • | icmp        | -1        | -1      | 0.0.0.0/0 |              |  
  • | tcp         | 22        | 22      | 0.0.0.0/0 |              |  
  • |             |           |         |           | default      |  
  • | udp         | 53        | 53      | 0.0.0.0/0 |              |  
  • +-------------+-----------+---------+-----------+--------------+

[color=#336699 !important]复制代码
  

删除某个实例, 使用中的规则

  • nova remove-secgroup terry_instance1 terry

[color=#336699 !important]复制代码
  

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



openstack 命令行管理:内部网络[instance专用]管理 
ip 帮助

  • [iyunv@station140 ~(keystone_admin)]# nova help | grep ip  
  •     add-fixed-ip        Add new IP address on a network to server.  
  •     add-floating-ip     Add a floating IP address to a server.  
  •     cloudpipe-configure  
  •                         Update the VPN IP/port of a cloudpipe instance.  
  •     cloudpipe-create    Create a cloudpipe instance for the given project.  
  •     cloudpipe-list      Print a list of all cloudpipe instances.  
  •     dns-create          Create a DNS entry for domain, name and ip.  
  •     dns-list            List current DNS entries for domain and ip or domain  
  •     fixed-ip-get        Retrieve info on a fixed ip.  
  •     fixed-ip-reserve    Reserve a fixed IP.  
  •     fixed-ip-unreserve  Unreserve a fixed IP.  
  •     floating-ip-bulk-create  
  •                         Bulk create floating ips by range.  
  •     floating-ip-bulk-delete  
  •                         Bulk delete floating ips by range.  
  •     floating-ip-bulk-list  
  •                         List all floating ips.  
  •     floating-ip-create  Allocate a floating IP for the current tenant.  
  •     floating-ip-delete  De-allocate a floating IP.  
  •     floating-ip-list    List floating ips for this tenant.  
  •     floating-ip-pool-list  
  •                         List all floating ip pools.  
  •     remove-fixed-ip     Remove an IP address from a server.  
  •     remove-floating-ip  Remove a floating IP address from a server.  

[color=#336699 !important]复制代码
  

网络管理帮助

  • [iyunv@station140 ~(keystone_admin)]# nova help | grep network  
  •     interface-attach    Attach a network interface to an instance.  
  •     interface-detach    Detach a network interface from an instance.  
  •     network-associate-host  
  •                         Associate host with network.  
  •     network-associate-project  
  •                         Associate project with network.  
  •     network-create      Create a network.  
  •     network-disassociate  
  •                         network.  
  •     network-list        Print a list of available networks.  
  •     network-show        Show details about the given network.  
  •     reset-network       Reset network of an instance.  
  •                         Add a network interface to a baremetal node.  
  •                         List network interfaces associated with a baremetal  
  •                         Remove a network interface from a baremetal node.  
  •     net                 Show a network  
  •     net-create          Create a network  
  •     net-delete          Delete a network  
  •     net-list            List networks  

[color=#336699 !important]复制代码
  

显示当前 openstack 网络方法

  • [iyunv@station140 ~(keystone_admin)]# nova network-list  
  • +--------------------------------------+---------+------+  
  • | ID                                   | Label   | Cidr |  
  • +--------------------------------------+---------+------+  
  • | 68a1d874-e7bd-42e2-9f86-8eb0b0b4b8fd | public  | None |  
  • | e8e14001-44d9-4ab1-a462-ea621b8a4746 | private | None |  
  • +--------------------------------------+---------+------+  

[color=#336699 !important]复制代码
  

参考 openstack 官方文档, 在某些旧版本中, 需要利用下面方法创建网络, 当前 H 版本可以不使用下面变量

  • export OS_USERNAME=admin  
  • export OS_PASSWORD=password  
  • export OS_TENANT_NAME=admin  
  • export OS_AUTH_URL=http://localhost:5000/v2.0

[color=#336699 !important]复制代码
  

另外一种列出网络方法

  • [iyunv@station140 ~(network_admin)]# neutron net-list  
  • +--------------------------------------+---------+------------------------------------------------------+  
  • | id                                   | name    | subnets                                              |  
  • +--------------------------------------+---------+------------------------------------------------------+  
  • | 68a1d874-e7bd-42e2-9f86-8eb0b0b4b8fd | public  | ce0a4a92-5c23-4557-ad67-97560ab5afa1 172.24.4.224/28 |  
  • | e8e14001-44d9-4ab1-a462-ea621b8a4746 | private | 79fdeabd-7f8a-4619-a17d-87864ccdfa80 10.0.0.0/24     |  
  • +--------------------------------------+---------+------------------------------------------------------+

[color=#336699 !important]复制代码
  

显示某个网络详细信息

  • [iyunv@station140 ~(network_admin)]# neutron net-show public  
  • +---------------------------+--------------------------------------+  
  • | Field                     | Value                                |  
  • +---------------------------+--------------------------------------+  
  • | admin_state_up            | True                                 |  
  • | id                        | 68a1d874-e7bd-42e2-9f86-8eb0b0b4b8fd |  
  • | name                      | public                               |  
  • | provider:network_type     | local                                |  
  • | provider:physical_network |                                      |  
  • | provider:segmentation_id  |                                      |  
  • | router:external           | True                                 |  
  • | shared                    | False                                |  
  • | status                    | ACTIVE                               |  
  • | subnets                   | ce0a4a92-5c23-4557-ad67-97560ab5afa1 |  
  • | tenant_id                 | e3a71a59840c4e88b8740b789c3afb9c     |  
  • +---------------------------+--------------------------------------+  

[color=#336699 !important]复制代码
  

显示网络 extension 详细信息

  • [iyunv@station140 ~(keystone_admin)]# neutron ext-list  
  • +-----------------------+-----------------------------------------------+  
  • | alias                 | name                                          |  
  • +-----------------------+-----------------------------------------------+  
  • | ext-gw-mode           | Neutron L3 Configurable external gateway mode |  
  • | security-group        | security-group                                |  
  • | l3_agent_scheduler    | L3 Agent Scheduler                            |  
  • | provider              | Provider Network                              |  
  • | binding               | Port Binding                                  |  
  • | quotas                | Quota management support                      |  
  • | agent                 | agent                                         |  
  • | dhcp_agent_scheduler  | DHCP Agent Scheduler                          |  
  • | external-net          | Neutron external network                      |  
  • | router                | Neutron L3 Router                             |  
  • | allowed-address-pairs | Allowed Address Pairs                         |  
  • | extra_dhcp_opt        | Neutron Extra DHCP opts                       |  
  • | extraroute            | Neutron Extra Route                           |  
  • +-----------------------+-----------------------------------------------+  

[color=#336699 !important]复制代码
  

创建私有网络

  • [iyunv@station140 ~(network_admin)]# neutron net-create net1  
  • Created a new network:  
  • +---------------------------+--------------------------------------+  
  • | Field                     | Value                                |  
  • +---------------------------+--------------------------------------+  
  • | admin_state_up            | True                                 |  
  • | id                        | d0e3f988-d62f-4f95-ab21-b73f4dae326b |  
  • | name                      | net1                                 |  
  • | provider:network_type     | local                                |  
  • | provider:physical_network |                                      |  
  • | provider:segmentation_id  |                                      |  
  • | shared                    | False                                |  
  • | status                    | ACTIVE                               |  
  • | subnets                   |                                      |  
  • | tenant_id                 | e3a71a59840c4e88b8740b789c3afb9c     |  
  • +---------------------------+--------------------------------------+  

[color=#336699 !important]复制代码
  

显示 net1 网络详细信息

  • [iyunv@station140 ~(keystone_admin)]# neutron net-show net1  
  • +---------------------------+--------------------------------------+  
  • | Field                     | Value                                |  
  • +---------------------------+--------------------------------------+  
  • | admin_state_up            | True                                 |  
  • | id                        | d0e3f988-d62f-4f95-ab21-b73f4dae326b |  
  • | name                      | net1                                 |  
  • | provider:network_type     | local                                |  
  • | provider:physical_network |                                      |  
  • | provider:segmentation_id  |                                      |  
  • | router:external           | False                                |  
  • | shared                    | False                                |  
  • | status                    | ACTIVE                               |  
  • | subnets                   |                                      |  
  • | tenant_id                 | e3a71a59840c4e88b8740b789c3afb9c     |  
  • +---------------------------+--------------------------------------+  

[color=#336699 !important]复制代码
  

创建私网络 net1 的子网

  • [iyunv@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  
  • Created a new subnet:  
  • +------------------+---------------------------------------------+  
  • | Field            | Value                                       |  
  • +------------------+---------------------------------------------+  
  • | allocation_pools | {"start": "10.0.0.50", "end": "10.0.0.100"} |  
  • | cidr             | 10.0.0.0/24                                  |  
  • | dns_nameservers  |                                             |  
  • | enable_dhcp      | True                                        |  
  • | gateway_ip       |                                             |  
  • | host_routes      |                                             |  
  • | id               | 3066c397-bccf-4473-8a94-72b09a97a70a        |  
  • | ip_version       | 4                                           |  
  • | name             | terry_pri_net1                              |  
  • | network_id       | d0e3f988-d62f-4f95-ab21-b73f4dae326b        |  
  • | tenant_id        | e3a71a59840c4e88b8740b789c3afb9c            |  
  • +------------------+---------------------------------------------+  

[color=#336699 !important]复制代码
  

显示 net1 网络详细信息

  • [iyunv@station140 ~(keystone_admin)]# neutron net-show net1  
  • +---------------------------+--------------------------------------+  
  • | Field                     | Value                                |  
  • +---------------------------+--------------------------------------+  
  • | admin_state_up            | True                                 |  
  • | id                        | d0e3f988-d62f-4f95-ab21-b73f4dae326b |  
  • | name                      | net1                                 |  
  • | provider:network_type     | local                                |  
  • | provider:physical_network |                                      |  
  • | provider:segmentation_id  |                                      |  
  • | router:external           | False                                |  
  • | shared                    | False                                |  
  • | status                    | ACTIVE                               |  
  • | subnets                   | 3066c397-bccf-4473-8a94-72b09a97a70a |  
  • | tenant_id                 | e3a71a59840c4e88b8740b789c3afb9c     |  
  • +---------------------------+--------------------------------------+  

[color=#336699 !important]复制代码
  

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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-162041-1-1.html 上篇帖子: OpenStack版本升级之Keystone 下篇帖子: OpenStack版本升级之Glance
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表