![firewalld:兩張網卡,兩個區域。區域被忽略](https://rvso.com/image/747330/firewalld%EF%BC%9A%E5%85%A9%E5%BC%B5%E7%B6%B2%E5%8D%A1%EF%BC%8C%E5%85%A9%E5%80%8B%E5%8D%80%E5%9F%9F%E3%80%82%E5%8D%80%E5%9F%9F%E8%A2%AB%E5%BF%BD%E7%95%A5.png)
我有一台運行 CentOS/RHEL 7.7 的伺服器,有兩個網路介面。這些介面已配置並正常運作。第一個介面 ens33 是firewalld「公共」區域的一部分。應用於該區域的所有規則都可以正常運作。當作為「公共」區域的成員時,第二個介面 ens37 也可以如預期般運作。我創建了第二個區域“GLZ”,它具有一組特定於第二個介面的功能的規則。我無法從 GLZ 區域獲取任何規則以在此介面上生效。我過去多次使用 iptables 配置這種類型的設置,但似乎無法透過 firewalld 獲得所需的效果。我覺得我一定錯過了一些關於firewalld的基本功能,但我不知道它可能是什麼。以下是具體情況:
設定腳本:
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