1. Direct Rule
1)直接使用iptables或firewall语句将规则写入管理区域中。
2)执行优先级最高,优先规则:直接规则→富规则→区域规则
3)firewall语句与iptables语句互相通用
4)使用于服务或应用程序。
Statement format:
firewall-cmd --direct
例1:启用黑名单
firewall-cmd --direct --add-chain ipv4 raw blacklist
例2:将来自黑名单的数据包丢弃
fireall-cmd --direct --add-rule ipv4 raw blacklist 1 -j DROP
2. Rich language
Time statements or expressions described in more detail, including refuse permission. Configure logging, port forwarding, masquerading, rate limiting, access time.
Statement format
firewall-cmd --zone = area --add-rich-rule = 'rule-rich regular expression'
Note: Regional Options are optional. If you do not use Regional Options, expressed as add all areas.
为所有区域添加富规则:
firewall-cmd --add-rich-rule
删除富规则
firewall-cmd --remove-rich-rule
查看rule规则是否添加到指定的区域
firewall-cmd --query-rich-rule
查看富规则列表
firewall-cmd --list-rich-rule
3. Rich regular expressions
Format:
firewall-cmd --zone = area --add-rich-rule "rule action feature type option"
- Options
source address=源IP地址
destination address= 目标IP地址
log=日志管理
log prefix=日志文件
level=日志级别
limit value=条数/时间 记录日志周期
- Feature type:
server name=服务名
port port=端口号
Protocol value=协议类型(TCP/UDP)
icmp-block name=ICMP数据包类型(request reply)
masquerade 转换地址与端口号
- action
audit:审核
accept:通过
drop:拒绝、丢弃
reject:拒绝并返回信息
--timeout=300 300秒,只限制5分钟。
- Examples
例1:在external区域中,为认证包头协议AH使用新的ipv4和ipv6连接
firewall-cmd --zone=external --add-rich-rule='rule protocol value=ah accept'
例2:允许ipv4的主机访问FTP服务,并使用审核记录每分钟记录一次
firewall-cmd --zone=internal --add-rich-rule='rule family=ipv4 service name=ftp log limit value=1/m audit accept'