主机模式 Docker 会绕过群晖防火墙? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要把任何和邀请码有关的内容发到 NAS 节点。

邀请码相关的内容请使用 /go/in 节点。

如果没有发送到 /go/in,那么会被移动到 /go/pointless 同时账号会被降权。如果持续触发这样的移动,会导致账号被禁用。
LnTrx
V2EX    NAS

主机模式 Docker 会绕过群晖防火墙?

  •  
  •   LnTrx 2023-0212 00:54:08 +08:00 3456 次点击
    这是一个创建于 974 天前的主题,其中的信息可能已经有所发展或是发生改变。

    为了能公网访问 IPv6 ,容器选择了 host 模式的网络。然后发现容器内程序绑定的端口可以在外网直接访问,不像 bridge 映射端口的 docker 需要修改防火墙配置。

    想确认一下,主机模式下容器会绕过防火墙,是群晖的特性,还是有配置有误?是否能通过 UI 中的选项修改?(威联通的 QuFireWall 是能挡住的)

    8 条回复    2025-07-04 15:40:45 +08:00
    smallparking
        1
    smallparking  
       2023-02-12 01:11:36 +08:00 via Android
    是的,容器使用主机模式的网络可以绕过主机上的防火墙。

    在主机模式下,容器直接使用主机的网络栈,并且容器上的端口映射到主机上。因此,外部访问者可以直接访问容器上的服务,不会受到主机上的防火墙的限制。

    如果您希望容器的网络连接受到防火墙的保护,则应该使用网络隔离技术,例如:使用网络命名空间、桥接模式、macvlan 等。
    LnTrx
        2
    LnTrx  
    OP
       2023-02-12 01:27:50 +08:00   2
    @smallparking 用 macvlan 恐怕防火墙更挡不住了。不过也好奇,威联通是怎么挡住的,底层设计是什么。
    顺便也想提议,社区应该规定必须标注 AI 回答。
    32uKHwVJ179qCmPj
        3
    32uKHwVJ179qCmPj  
       2023-02-12 09:49:01 +08:00
    1L 真恶心

    我特意测试了下,有 ipv6 公网 ip ,无 ipv4 公网 ip ,但 docker 显示 host 模式已禁用,群晖防火墙能防住
    lujjjh
        4
    lujjjh  
       2023-02-12 10:48:24 +08:00
    遇到过类似的问题,但不是在群晖上,表现是容器映射出的端口会绕过 ufw 规则限制(还好配置完 ufw 之后测试了一下,不然服务就暴露公网了)。

    原因是容器端口映射是通过 iptables 规则实现的,而 ufw 插入到 iptables 里的规则没有作用于 DOCKER-USER 链,参考:
    https://docs.docker.com/network/iptables/
    https://github.com/docker/for-linux/issues/690

    不知道群晖的防火墙是怎么工作的,可以检查一下 iptables 看看你是不是同样的情况。看了上面的 issue ,我比较意外 --net=host 开放的端口也是走 iptables 的?
    littlewing
        5
    littlewing  
       2023-02-12 11:04:49 +08:00
    **Add iptables policies before Docker’s rules**
    Docker installs two custom iptables chains named DOCKER-USER and DOCKER, and it ensures that incoming packets are always checked by these two chains first.

    All of Docker’s iptables rules are added to the DOCKER chain. Do not manipulate this chain manually. If you need to add rules which load before Docker’s rules, add them to the DOCKER-USER chain. These rules are applied before any rules Docker creates automatically.

    Rules added to the FORWARD chain -- either manually, or by another iptables-based firewall -- are evaluated after these chains. This means that if you expose a port through Docker, this port gets exposed no matter what rules your firewall has configured. If you want those rules to apply even when a port gets exposed through Docker, you must add these rules to the DOCKER-USER chain.
    kenvix
        6
    kenvix  
       2023-02-12 13:15:59 +08:00
    @smallparking 虽然没什么问题,但是这个回答不会是 ChatGPT 吧
    huazhaozhe
        7
    huazhaozhe  
       100 天前
    @smallparking #1
    @LnTrx
    群晖测试 docker host 下使用 nmap 扫端口是 filtered 防火墙是生效的不要误导人
    LnTrx
        8
    LnTrx  
    OP
       100 天前
    @huazhaozhe 现在版本防火墙正确配置的话是有效的
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3595 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 27ms UTC 04:30 PVG 12:30 LAX 21:30 JFK 00:30
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86