我有一台运行 CentOS/RHEL 7.7 的服务器,它有两个网络接口。这些接口已配置并正常工作。第一个接口 ens33 是防火墙“公共”区域的一部分。应用于此区域的所有规则均正常工作。第二个接口 ens37 在作为“公共”区域的成员时也能正常工作。我创建了第二个区域“GLZ”,它有一组特定于第二个接口功能的规则。我无法从 GLZ 区域获取任何规则以在此接口上生效。我过去曾多次使用 iptables 配置此类设置,但似乎无法通过防火墙获得预期的效果。我觉得我一定是缺少了防火墙的一些基本功能,但我不知道那是什么。以下是具体内容:
安装脚本:
NEWZONE="GLZ"
# create the new zone
firewall-cmd --permanent --new-zone=$NEWZONE
firewall-cmd --reload
# add the second NIC to the zone
firewall-cmd --permanent --zone=$NEWZONE --change-interface=ens37
# set zone target
firewall-cmd --zone=$NEWZONE --permanent --set-target=default
firewall-cmd --reload
# open necessary ports
firewall-cmd --permanent --zone=$NEWZONE --add-rich-rule='rule family=ipv4 source address=0.0.0.0/0 port protocol=tcp port=80 accept'
firewall-cmd --permanent --zone=$NEWZONE --add-rich-rule='rule family=ipv4 source address=0.0.0.0/0 port protocol=tcp port=443 accept'
# setup forwarding (see https://docs.fedoraproject.org/en-US/Fedora/19/html/Security_Guide/sec-Configure_Port_Forwarding-CLI.html)
firewall-cmd --permanent --zone=$NEWZONE --add-masquerade
firewall-cmd --permanent --zone=$NEWZONE --add-forward-port=port=22:proto=tcp:toport=2222
firewall-cmd --reload
根据 --info-zone 的输出,这似乎没问题。两个区域都处于活动状态,并且每个区域都分配了适当的网络接口。我对公共区域所做的任何更改都会影响两个接口上的流量,而我在 GLZ 区域中添加或删除的任何规则都没有任何区别。
输出:
$ sudo firewall-cmd --info-zone=public
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule family="ipv4" source address="10.0.0.0/8" port port="3306" protocol="tcp" accept
rule family="ipv4" source address="10.0.0.0/8" port port="80" protocol="tcp" accept
rule family="ipv4" source address="10.0.0.0/8" port port="443" protocol="tcp" accept
rule family="ipv4" source address="10.0.0.0/8" port port="8080" protocol="tcp" accept
$ sudo firewall-cmd --info-zone=GLZ
GLZ (active)
target: default
icmp-block-inversion: no
interfaces: ens37
sources:
services:
ports:
protocols:
masquerade: yes
forward-ports: port=22:proto=tcp:toport=2222:toaddr=
source-ports:
icmp-blocks:
rich rules:
rule family="ipv4" source address="0.0.0.0/0" port port="80" protocol="tcp" accept
rule family="ipv4" source address="0.0.0.0/0" port port="443" protocol="tcp" accept