docker防火墙使用的是底层iptables,封装后的firewalld默认不生效

如果想要使用firewalld,需要做以下调整:

让firewalld移除DOCKER-USER并新建一个

# Removing DOCKER-USER CHAIN (it won't exist at first)
firewall-cmd --permanent --direct --remove-chain ipv4 filter DOCKER-USER # Flush rules from DOCKER-USER chain (again, these won't exist at first; firewalld seems to remember these even if the chain is gone)
firewall-cmd --permanent --direct --remove-rules ipv4 filter DOCKER-USER # Add the DOCKER-USER chain to firewalld
firewall-cmd --permanent --direct --add-chain ipv4 filter DOCKER-USER

加上你想要的规则,注意reject放在最后

firewall-cmd --permanent --direct --add-rule ipv4 filter DOCKER-USER 0 -i docker0 -j ACCEPT -m comment --comment "allows incoming from docker"
firewall-cmd --permanent --direct --add-rule ipv4 filter DOCKER-USER 0 -i docker0 -o eth0 -j ACCEPT -m comment --comment "allows docker to eth0"
firewall-cmd --permanent --direct --add-rule ipv4 filter DOCKER-USER 0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -m comment --comment "allows docker containers to connect to the outside world"
firewall-cmd --permanent --direct --add-rule ipv4 filter DOCKER-USER 0 -j RETURN -s 172.17.0.0/16 -m comment --comment "allow internal docker communication" ## 你可以直接允許來自特定 IP 的所有流量
firewall-cmd --permanent --direct --add-rule ipv4 filter DOCKER-USER 0 -s 61.222.3.133/32 -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv4 filter DOCKER-USER 0 -j REJECT --reject-with icmp-host-unreachable -m comment --comment "reject all other traffic"

最后reload,并通过iptables -L确认是否正确生效

firewall-cmd --reload

参考链接:

https://holywhite.com/archives/489

centos7 docker配置防火墙firewalld的更多相关文章

  1. CentOS7下配置防火墙放过Keepalived

    Keepalived是一个轻量级的HA集群解决方案,但开启防火墙后各节点无法感知其它节点的状态,各自都绑定了虚拟IP.网上很多文章讲要配置防火墙放过tcp/112,在CentOS7下是无效的,正确的做 ...

  2. Centos7 Docker配置TLS认证的远程端口的证书生成教程(shell脚本一键生成)

    通过 TLS来进行远程访问 百度百科 - TLS.我们需要在远程 docker 服务器(运行 docker 守护进程的服务器)生成 CA 证书,服务器证书,服务器密钥,然后自签名,再颁发给需要连接远程 ...

  3. centOS7.0配置防火墙

    之前用的iptables来管理的防火墙,后来发现centOS7.0中已经用firewalld取代iptables了,于是与时俱进,停用了iptables. systemctl stop iptable ...

  4. Centos7 systemctl和防火墙firewalld命令(参考https://www.cnblogs.com/marso/archive/2018/01/06/8214927.html)

    一.防火墙的开启.关闭.禁用命令 (1)设置开机启用防火墙:systemctl enable firewalld.service (2)设置开机禁用防火墙:systemctl disable fire ...

  5. 新装Centos7.2 配置防火墙

    1.安装 yum -y install firewalld2.开机启动 systemctl enable firewalld3.设置防火墙规则 systemctl restart firewalld ...

  6. Ubuntu下使用UFW,以及CentOS7的默认防火墙firewalld

    UFW是一个简化版的iptables,基于iptables,配置比iptables简单 默认UFW是关闭状态,即Ubuntu默认打开所有端口,比较危险. 检测状态 ufw status 设置默认状态, ...

  7. Linux centos7.0 配置防火墙及开放端口

    现在防火墙有两种服务1.service firewalld 2.service iptables 一.就firewalld来说查看开放的端口  netstat  -anp 查询防火墙状态  servi ...

  8. CentOS7.3防火墙firewalld简单配置

    今天安装了centos7.3, 想用iptables的save功能保存规则的时候发现跟rhel不一样了,  后来度娘说centos用的是firewalld而不是iptables了, 平时工作都是用re ...

  9. Linux防火墙配置(iptables, firewalld)

    netfilter和底层实现 iptables firealld Linux中的防火墙 RHEL中有几种防火墙共存: iptables firewalld ip6tables ebtables 这些软 ...

  10. CentOS7下Firewall防火墙配置用法详解

    官方文档地址: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide ...

随机推荐

  1. Flask-SQLAlchemy常用新旧查询语法对比

    https://docs.sqlalchemy.org/en/20/tutorial/data.html 新旧版语法的说明 在2.x的SQLALchemy中,查询语法为: db.session.exe ...

  2. Docker部署系列之Docker Compose安装Redis三主三从集群

    总结/朱季谦 在日常开发或者编程当中,经常需要用到redis集群,若是按照传统的方式,一个机器一个机器搭建,难免过于繁琐,故而可以通过dock er-compose编排方式,快速搭建.我在搭建过程当中 ...

  3. Asp .Net Core 集成 FluentValidation 强类型验证规则库

    目录 入门程序 安装 案例:登录 验证器 内置验证器 自定义验证器 编写自定义验证器 可重复使用的属性验证器 本地化 DI 自动验证 官网:https://docs.fluentvalidation. ...

  4. 春秋云镜 - CVE-2022-28060

    Victor CMS v1.0 /includes/login.php 存在sql注入 找到页面的登录框,看介绍应该是post类型的表单注入. 上sqlmap用原本的梭发现ctf的那个表是空的,换用- ...

  5. Python中numpy出现has no attribute '_no_nep50_warning'错误的一个解决方案

      本文介绍在Python中,numpy库出现报错module 'numpy' has no attribute '_no_nep50_warning'的解决方法.   一次,在运行一个Python代 ...

  6. Java异常中处理return

    Java中的return语句 在Java中,return语句用于从一个方法中返回结果,并终止当前方法的执行.在方法中使用return语句后,后续的语句将不会执行. public int add(int ...

  7. 文心一言 VS 讯飞星火 VS chatgpt (51)-- 算法导论6.2 3题

    三.当元素 A[i] 比其孩子的值都大时,调用 MAX-HEAPIFY(A.i)会有什么结果? 文心一言: 当元素 A[i] 比其孩子的的值都大时,调用 MAX-HEAPIFY(A, i) 会将 A[ ...

  8. JAVAEE基础知识

    JAVAEE基础知识 2018年3月,开源组织Eclipse基金会宣布,JavaEE(Enterprise Edition)被更名为JakartaEE,也就是9版本后改名Jakarta EE,也就是J ...

  9. flink 笔记

    flink 分区实现 http://smartsi.club/physical-partitioning-in-apache-flink.html

  10. 中国人的 Java 生态,Solon v2.5.3 发布

    Solon 是什么? 国产的 Java 应用开发框架.从零开始构建,有自己的标准规范与开放生态(历时五年,具备全球第二级别的生态规模).与其他框架相比,解决了两个重要的痛点:启动慢,费内存. 关键记事 ...