如何解决 Linux 防火墙完全失效的问题? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
naohion
V2EX    Linux

如何解决 Linux 防火墙完全失效的问题?

  •  
  •   naohion 2020-08-11 02:44:57 +08:00 2388 次点击
    这是一个创建于 1970 天前的主题,其中的信息可能已经有所发展或是发生改变。

    CentOS 7 的服务器,之前配置 IPv6 一直无法使用,没去管,今天随手扫了一下开放端口发现 firewalld 规则里没有开放的端口全部被开放了。确定 zone 设置正确,firewalld 和 iptables 都在正常工作,规则都已正常保存。然后我加了一条 iptables 拒绝规则,然而还是可以访问。firewalld 打开 panic 模式照样能 ssh 连接服务器。不知道这和 IPv6 无效是否有关,请问有大佬知道吗?研究了一天还没解决。

    第 1 条附言    2020-08-11 17:26:58 +08:00
    已经解决了,是 docker 的问题,会添加 chain 绕过 iptables 。网络上的方案全试过一遍,只有启动容器时指定 -p 127.0.0.1:x:x 的有效。这里提供一个自己研究出来的一键更新 0.0.0.0 -> 127.0.0.1 的命令有需要的可以拿去用。
    systemctl stop docker;
    cd /var/lib/docker;
    find -name '*.json' | xargs perl -pi -e 's|"HostIp":""|"HostIp":"127.0.0.1"|g'; (这条很重要)
    find -name '*.json' | xargs perl -pi -e 's|0.0.0.0|127.0.0.1|g';
    systemctl start docker
    zwl2012
        1
    zwl2012  
       2020-08-11 08:51:10 +08:00 via iPhone
    docker
    snoopygao
        2
    snoopygao  
       2020-08-11 08:58:08 +08:00
    贴出来 list-all-zone 看看
    naohion
        3
    naohion  
    OP
       2020-08-11 10:04:01 +08:00
    @zwl2012 一直在用 docker 但一些容器的端口不希望外网访问

    @snoopygao $ sudo firewall-cmd --list-all-zone
    [sudo] password for user:
    block
    target: %%REJECT%%
    icmp-block-inversion: no
    interfaces:
    sources:
    services:
    ports:
    protocols:
    masquerade: no
    forward-ports:
    source-ports:
    icmp-blocks:
    rich rules:


    dmz
    target: default
    icmp-block-inversion: no
    interfaces:
    sources:
    services: ssh
    ports:
    protocols:
    masquerade: no
    forward-ports:
    source-ports:
    icmp-blocks:
    rich rules:


    drop
    target: DROP
    icmp-block-inversion: no
    interfaces:
    sources:
    services:
    ports:
    protocols:
    masquerade: no
    forward-ports:
    source-ports:
    icmp-blocks:
    rich rules:


    external
    target: default
    icmp-block-inversion: no
    interfaces:
    sources:
    services: ssh
    ports:
    protocols:
    masquerade: yes
    forward-ports:
    source-ports:
    icmp-blocks:
    rich rules:


    home
    target: default
    icmp-block-inversion: no
    interfaces:
    sources:
    services: dhcpv6-client mdns samba-client ssh
    ports:
    protocols:
    masquerade: no
    forward-ports:
    source-ports:
    icmp-blocks:
    rich rules:


    internal
    target: default
    icmp-block-inversion: no
    interfaces:
    sources:
    services: dhcpv6-client mdns samba-client ssh
    ports:
    protocols:
    masquerade: no
    forward-ports:
    source-ports:
    icmp-blocks:
    rich rules:


    public (active)
    target: default
    icmp-block-inversion: no
    interfaces: eth0
    sources:
    services: dhcpv6-client ssh
    ports: 443/tcp 22/tcp 80/tcp
    protocols:
    masquerade: no
    forward-ports:
    source-ports:
    icmp-blocks:
    rich rules:


    trusted
    target: ACCEPT
    icmp-block-inversion: no
    interfaces:
    sources:
    services:
    ports:
    protocols:
    masquerade: no
    forward-ports:
    source-ports:
    icmp-blocks:
    rich rules:


    work
    target: default
    icmp-block-inversion: no
    interfaces:
    sources:
    services: dhcpv6-client ssh
    ports:
    protocols:
    masquerade: no
    forward-ports:
    source-ports:
    icmp-blocks:
    rich rules:
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2462 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 23ms UTC 08:29 PVG 16:29 LAX 00:29 JFK 03:29
    Do have faith in what you're doing.
    ubao msn 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