【问题标题】:How to correct configuration for firewalld and docker/nginx?如何更正 firewalld 和 docker/nginx 的配置?
【发布时间】:2021-06-10 00:11:39
【问题描述】:

我有一个 CentOS 7 服务器,它运行了 600 多天,直到它最近重新启动,之后传入的 Web 请求收到 HTTP523(源无法访问)错误代码(通过 Cloudflare,如果这有什么不同?)除非我停止了firewalld 服务。没有firewalld 一切正常,但我宁愿不要让它禁用!

我尝试停止 dockerfirewalld 并以各种顺序重新启动它们,但除非我停止 firewalld,否则会出现相同的 523 错误。

/var/log/firewalld 包含一些可能有帮助的警告:

  • WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i br-8acb606a3b50 -o br-8acb606a3b50 -j DROP' failed: iptables: Bad rule (does a matching rule exist in that chain?).
  • WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (does a matching rule exist in that chain?).
  • WARNING: AllowZoneDrifting is enabled. This is considered a n insecure configuration option. It will be removed in a future release. Please consider disabling it now.
  • WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -D PREROUTING -m addrtype --dst-type LOCAL -j DOCKER' failed: iptables v1.4.21: Couldn't load target 'DOCKER':No such file or directory
  • WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -D PREROUTING' failed: iptables: Bad rule (does a matching rule exist in that chain?).
  • WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -D OUTPUT' failed: iptables: Bad rule (does a matching rule exist in that chain?)
  • WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -t nat -F DOCKER' failed: iptables: No chain/target/match by that name.

我发现关于所需的任何手动配置/命令的建议似乎相互矛盾:

  1. firewall-cmd --permanent --zone=trusted --add-interface=docker0 on a CentOS forum
  2. firewall-cmd --zone=trusted --remove-interface=docker0 --permanent on the offical Docker docs -- 肯定与上面的相反吗?
  3. a bunch of manual firewall-cmd commands on a Docker github issue -- 肯定不需要所有这些吗?
  4. 这个看起来很有希望——nmcli, NetworkManager and firewall-cmd --permanent --zone=trusted --change-interface=docker0

我不完全了解br-8acb606a3b50 接口的来源,或者如果我使用上述4. 之类的解决方案,我是否需要做任何事情来配置它以及docker0?在重新启动之前,它多年来一直自动运行良好!

现在需要一些魔法firewalld 咒语(为什么?!)还是有什么方法可以让系统恢复到重新启动之前的正确自动/默认配置?

$ docker -v
Docker version 20.10.5, build 55c4c88
$ firewall-cmd --version
0.6.3
$ firewall-cmd --get-zones
block dmz docker drop external home internal public trusted work

【问题讨论】:

  • 你的 Docker 版本是多少?还请添加firewall-cmd --get-zones 显示的内容。
  • 附加版本/区域数据以供提问,谢谢
  • 什么是 CentOS 次要版本? 7.2、7.3 中有一个错误,在 7.4 之后的某个时间点已修复。这是解释和可能的修复12
  • 那么奇怪。症状看起来类似于解决方案 4 中描述的症状。当与firewalld 一起运行 Docker 时,它应该将其所有接口('docker0'、'br-8acb606a3b50'等)添加到'docker' firewalld 区域。您确实拥有该区域,但不知何故,iptables 中仍然没有 DOCKER 链(“没有该名称的链/目标/匹配”)。让我们看看'docker0'接口在哪里:firewall-cmd --get-zone-of-interface=docker0
  • 好吧,最后两件事:nmcli connection show docker0 | grep zonels /etc/sysconfig/network-scripts/ifcfg-*。如果第一个没有返回任何内容,而第二个你没有看到 docker0,我建议你使用解决方案 4。

标签: docker nginx centos7 cloudflare firewalld


【解决方案1】:

回顾chat investigation,这个特殊问题与 Docker 和容器无关。问题在于firewalld 没有规则让NGINX 作为主机上容器的代理运行。解决方案是为 HTTP 和 HTTPS 流量添加永久防火墙规则:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

类似这样的警告信息:

WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w10 -D FORWARD -i br-8acb606a3b50 -o br-8acb606a3b50 -j DROP' failed: iptables: Bad rule(匹配规则是否存在于该链中?)

... 可以在正常操作期间出现,当 Docker 尝试删除规则而不首先检查其存在时。也就是说,即使有这样的警告,容器也能顺利运行。

【讨论】:

    【解决方案2】:

    我在使用 Podman 时遇到了一些类似的问题,对我来说,我必须从 Debian 9 升级到 Debian 10 才能修复它,因为 firewalld 处理 iptables 和 nftables 的方式。

    【讨论】:

    • 我无法想象如果不升级操作系统就无法解决这个问题!
    • @DrMeers 在我看来,您可以考虑更新操作系统并检查它是否可以解决您的问题。
    • CentOS 7 到 2024 年 6 月 30 日才结束生命周期
    猜你喜欢
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    • 2019-10-29
    • 2020-11-08
    • 1970-01-01
    • 2021-01-08
    相关资源
    最近更新 更多