规则参考

云防火墙规则适用于启用了云防火墙功能的同一数据中心中的所有计算实例。添加、更新或删除规则立即适用于这些计算实例。

默认规则

默认的云防火墙规则阻止所有传入流量并允许所有传出的流量。始终允许流量到ICMP type 8 code 0(ping)。

  • FROM any to all vms BLOCK TCP PORT all
  • FROM any to all vms BLOCK UDP PORT all
  • FROM any to all vms BLOCK ICMP (TYPE 0 AND TYPE 1 AND ... TYPE 255)
  • FROM all vms to any ALLOW TCP PORT all
  • FROM all vms to any ALLOW UDP PORT all
  • FROM any to all vms ALLOW ICMP TYPE 8 CODE 0

指定规则

from any to tag www allow tcp (port 80 and port 443)

云防火墙规则语法

以下各节提供了云防火墙规则的语法图和示例。

rule

rule ::= 'FROM' target_list 'TO' target_list action protocol
    Block or allow traffic (action) from target_list to target_list on the given protocol

target_list

target_list   ::= 'ANY'
                | 'ALL VMS'
                | '(' target ( 'OR' target )* ')'
                | target
术语 含义
ANY 互联网上的任何一台机器。
ALL VMS 此数据中心上启用了云防火墙功能的所有计算实例。

示例

  • 允许Internet上的任何计算机的HTTPS流量到此数据中心中的所有计算实例。 FROM any TO all vms ALLOW tcp port 80
  • 允许此数据中心中所有计算实例之间的SSH流量。 FROM all vms TO all vms ALLOW tcp port 22

注意all vms是指定义了开启了云防火墙功能的数据中心中的每个计算实例。

target

target   ::= 'IP ADDRESS'
          | 'SUBNET'
          | 'TAG' tag_string
          | 'TAG' tag_string '=' tag_value
          | 'VM' uuid
术语 含义
IP ADDRESS IPv4地址:nnn.nnn.nnn.nnn
SUBNET IPv4 CIDR 子网地址: nnn.nnn.nnn.nnn/mm
TAG tag_string 在数据中心中启用了云防火墙功能的任何计算实例,并具有tag_string 标签
TAG tag_string=tag_value 在数据中心中启用了云防火墙功能的任何计算实例,标签tag_stringtag_value
VM uuid 计算实例的uuid,计算实例必须位于数据中心且开启防火墙功能

示例

  • 不允许SMTP(端口25)流量到启用了云防火墙功能的同一数据中心上的IP 为10.2.0.1的计算实例。 FROM all vms to ip 10.2.0.1 BLOCK tcp port 25

  • 允许HTTPS(端口443)从私有子网到特定计算实例。 FROM subnet 10.8.0.0/16 TO vm 0f570678-c007-4610-a2c0-bbfcaab9f4e6 ALLOW tcp port 443

  • 允许此数据中心中任何计算实例的syslog(端口514)流量到此数据中心中具有标记syslog的任何计算实例。 FROM all vms TO tag syslog ALLOW udp port 514

  • 允许从数据库到Web服务器的数据库流量。具有不同角色标签的其他任何计算实例,比如role = staging不受此规则的影响。 FROM tag role = db TO tag role = www ALLOW tcp port 5432

  • 允许LDAP(端口389)流量从此数据中心的任何计算实例到具有标签VM typeLDAP服务器的计算实例。 FROM all vms TO tag "VM type" = "LDAP server" ALLOW tcp PORT 389

  • 只允许来自互联网上任何机器的HTTP流量到特定的计算实例。 FROM any to vm 04128191-d2cb-43fc-a970-e4deefe970d8 ALLOW tcp port 80

action

action ::= 'BLOCK'
         | 'ALLOW'
术语 含义
BLOCK 不允许流量
ALLOW 允许流量

Action可以是ALLOW或BLOCK之一。请注意,Action和方向的某些组合无效:

  • 由于默认规则集阻止所有传入端口,因此该规则不会对任何计算实例有影响。 FROM any TO all vms BLOCK tcp port 143
  • 由于默认规则允许所有传出流量,因此此规则不起作用。 FROM all vms TO any ALLOW tcp port 25

protocol

protocol ::= 'TCP' port_list
          | 'UDP' port_list
          | 'ICMP' type_list
术语 含义
TCP port_list 给定端口的TCP流量。
UDP port_list 给定端口的UDP流量。
ICMP type_list 给定类型和代码的ICMP流量。

对于TCP和UDP,需要指定规则所适用的端口号。端口号必须介于1到65535之间。 对于ICMP,它指定规则适用于的ICMP的TYPE和CODE。TYPE和CODE必须介于0到255之间。

  • 允许从任何IP到所有Web服务器的HTTP和HTTPS流量。 FROM tag www TO any ALLOW TCP (port 80 AND port 443)
  • 允许ping数据中心中的所有计算实例。这是一个默认规则。 FROM any TO all vms ALLOW icmp TYPE 8 CODE 0
  • 阻止来自数据中心中所有计算实例的传出ping响应。 FROM all vms TO any BLOCK icmp TYPE 0

port_list

port_list      ::= '(' port ( 'AND' port )* ')'
                | port
                | '(' 'PORT ALL' ')'
                | 'PORT ALL'
                | ports
术语 含义
PORT ALL 所有TCP或UDP端口:1 - 65535
port 单个TCP或UDP端口:1 - 65535
ports 端口一系列TCP或UDP端口:1 - 65535

port

port     ::= 'PORT' 1 - 65535
术语 含义
PORT nnn TCP或UDP端口号,范围为1 - 65535。

ports

ports     ::= 'PORTS' 1 - 65535
术语 含义
PORTS nnn 在mmm - nnn范围内的TCP或UDP端口号。

端口必须介于1到65535之间。

示例

  • 允许UDP流量从任何IP到所有标记的mosh服务器。

    FROM any TO tag mosh ALLOW udp PORTS 60000 - 61000

  • 允许TCP流量从任何网络服务器到所有标记的API服务器。

    FROM tag www TO tag api ALLOW tcp PORTS 10000 - 50000

type_list

type_list
        ::= '(' type ( 'AND' type )* ')'
          | type

type

type     ::= 'TYPE' 0 - 255 'CODE' 0 - 255
          | 'TYPE' 0 - 255
术语 含义
TYPE nnn CODE mmm 类型nnn和代码mmm的ICMP流量
TYPE nnn 类型nnn和任何代码的ICMP流量

TYPE和CODE的范围从0到255。

错误消息

无法创建某些规则,因为它们不会对数据中心中的任何计算实例产生影响。以下规则将导致“规则不影响虚拟机”错误消息。

FROM any TO any ALLOW tcp port 22

FROM ip 192.168.1.3 TO subnet 192.168.1.0/24 ALLOW tcp port 22

results matching ""

    No results matching ""