Centos

為什麼我在 CentOS 7 上的 Firewalld 配置無法啟動並顯示 iptables 錯誤?

  • December 21, 2014

我想:

  1. 刪除來自外部 Web 的所有傳入連接,80 和 443 除外
  2. 允許內部機器192.168.0.0/16連接到 :9000 :8080

這是我通過以下方式設置我的drop區域的方法firewall-cmd

echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
systemctl start firewalld.service
systemctl enable firewalld
firewall-cmd --set-default-zone=drop
firewall-cmd --permanent --zone=drop --add-service=ssh
firewall-cmd --permanent --zone=drop --add-port=80/tcp
firewall-cmd --permanent --zone=drop --add-port=443/tcp
firewall-cmd --zone=drop --permanent --add-rich-rule='rule source address="192.168.0.0/16" port port="9000" protocol="tcp" accept'
firewall-cmd --zone=drop --permanent --add-rich-rule='rule source address="192.168.0.0/16" port port="8080" protocol="tcp" accept'
firewall-cmd --reload

活動drop區域如下所示:

[root@machine ~]# firewall-cmd --zone=drop --list-all
drop (default, active)
 interfaces: eth0 vethadc7c41 vethaef84e2 vethd53fa38
 sources: 
 services: ssh
 ports: 443/tcp 80/tcp
 masquerade: no
 forward-ports: 
 icmp-blocks: 
 rich rules: 
 rule family="ipv4" source address="192.168.0.0/16" port port="9000" protocol="tcp" accept
 rule family="ipv4" source address="192.168.0.0/16" port port="8080" protocol="tcp" accept

這看起來不錯;但是,我在重新載入後遇到了問題:

[root@machine ~]# systemctl status firewalld -l
firewalld.service - firewalld - dynamic firewall daemon
  Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
  Active: active (running) since Sun 2014-12-21 19:48:53 UTC; 2s ago
Main PID: 21689 (firewalld)
  CGroup: /system.slice/firewalld.service
          └─21689 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

Dec 21 19:48:53 machine.hostname systemd[1]: Started firewalld - dynamic firewall daemon.
Dec 21 19:48:56 machine.hostname firewalld[21689]: 2014-12-21 19:48:56 ERROR: '/sbin/iptables -t filter -A DROP_allow -s 192.168.0.0/16 -m tcp -p tcp --dport 9000 -m conntrack --ctstate NEW -j ACCEPT' failed: iptables: No chain/target/match by that name.
Dec 21 19:48:56 machine.hostname firewalld[21689]: 2014-12-21 19:48:56 ERROR: '/sbin/iptables -t filter -A DROP_allow -s 192.168.0.0/16 -m tcp -p tcp --dport 9000 -m conntrack --ctstate NEW -j ACCEPT' failed: iptables: No chain/target/match by that name.
Dec 21 19:48:56 machine.hostname firewalld[21689]: 2014-12-21 19:48:56 ERROR: COMMAND_FAILED: '/sbin/iptables -t filter -A DROP_allow -s 192.168.0.0/16 -m tcp -p tcp --dport 9000 -m conntrack --ctstate NEW -j ACCEPT' failed: iptables: No chain/target/match by that name.
Dec 21 19:48:56 machine.hostname firewalld[21689]: 2014-12-21 19:48:56 ERROR: '/sbin/iptables -t filter -A DROP_allow -s 192.168.0.0/16 -m tcp -p tcp --dport 8080 -m conntrack --ctstate NEW -j ACCEPT' failed: iptables: No chain/target/match by that name.
Dec 21 19:48:56 machine.hostname firewalld[21689]: 2014-12-21 19:48:56 ERROR: '/sbin/iptables -t filter -A DROP_allow -s 192.168.0.0/16 -m tcp -p tcp --dport 8080 -m conntrack --ctstate NEW -j ACCEPT' failed: iptables: No chain/target/match by that name.
Dec 21 19:48:56 machine.hostname firewalld[21689]: 2014-12-21 19:48:56 ERROR: COMMAND_FAILED: '/sbin/iptables -t filter -A DROP_allow -s 192.168.0.0/16 -m tcp -p tcp --dport 8080 -m conntrack --ctstate NEW -j ACCEPT' failed: iptables: No chain/target/match by that name.

我有點困惑,因為我認為firewall-cmd這是一個抽象並且與 相互排斥iptables,後者是我​​不應該混淆的東西。

這是我的版本生命力:

[machine@douglasii ~]# firewall-cmd -V
0.3.9
[machine@douglasii ~]# cat /proc/version
Linux version 3.16.7-x86_64-linode49 (maker@build) (gcc version 4.7.2 (Debian 4.7.2-5) ) #3 SMP Fri Nov 14 16:55:37 EST 2014
[machine@douglasii ~]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core) 
[machine@douglasii ~]# iptables -v
iptables v1.4.21: no command specified
Try `iptables -h' or 'iptables --help' for more information.

您使用的 Linode 核心沒有您的防火牆需要的模組。這就是為什麼您會收到錯誤“沒有該名稱的鏈/目標/匹配”。

(而且 firewalld 是 iptables 的前端。)

要解決這個問題,需要執行虛擬機提供的核心,而不是 Linode 核心。通過將 Linode 設置為啟動pv-grub-x86_64,然後安裝核心(yum install kernel如果尚未安裝)來執行此操作。

引用自:https://serverfault.com/questions/654066