firewalld: 背后的原理(nftables)
一,firewalld对一个请求会适用哪个zone?
1, 当接收到一个请求时,firewalld具体使用哪个zone?
firewalld是通过三个步骤来判断的:
-
source,即:源地址
-
interface,即:接收请求的网卡
-
firewalld.conf中配置的默认zone
通常值为:DefaultZone=public
说明:三个步骤的优先级顺序降低
即:如果通过source匹配到了一个zone,
则不会再使用interface,
如果通过interface匹配到了zone,
则不会再使用默认zone
2, 为什么会是这样?这是firewalld的设置,
查看active-zones
[root@192 ~]# firewall-cmd --get-active-zones
drop
sources: 192.168.7.7
public
interfaces: ens33
trusted
sources: 192.168.8.8
查看default-zone
[root@192 ~]# firewall-cmd --get-default-zone
public
查看backend的nftables规则:
chain filter_INPUT_ZONES {
ip saddr 192.168.7.7 goto filter_IN_drop
ip saddr 192.168.8.8 goto filter_IN_trusted
iifname "ens33" goto filter_IN_public
goto filter_IN_public
}
二,firewalld的rich规则执行顺序:
1,执行顺序
1,日志规则
2,drop/reject规则
3,accept规则
2,列出所有规则
[root@192 ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
forward: yes
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule family="ipv4" source address="13.17.12.210" port port="22" protocol="tcp" accept
rule family="ipv4" source address="13.17.12.210" reject
查看nftables的规则:
chain filter_IN_public {
jump filter_INPUT_POLICIES_pre
jump filter_IN_public_pre
jump filter_IN_public_log
jump filter_IN_public_deny
jump filter_IN_public_allow
jump filter_IN_public_post
jump filter_INPUT_POLICIES_post
meta l4proto { icmp, ipv6-icmp } accept
reject with icmpx type admin-prohibited
}
这个顺序中,就是按 log/deny/allow的顺序执行