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

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

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

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

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

  1. firewall-cmd --permanent --direct --add-rule ipv4 filter DOCKER-USER 0 -i docker0 -j ACCEPT -m comment --comment "allows incoming from docker"
  2. firewall-cmd --permanent --direct --add-rule ipv4 filter DOCKER-USER 0 -i docker0 -o eth0 -j ACCEPT -m comment --comment "allows docker to eth0"
  3. 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"
  4. 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"
  5.  
  6. ## 你可以直接允許來自特定 IP 的所有流量
  7. firewall-cmd --permanent --direct --add-rule ipv4 filter DOCKER-USER 0 -s 61.222.3.133/32 -j ACCEPT
  8. 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确认是否正确生效

  1. 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. 整合SpringBoot + Dubbo + Nacos 出现 Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass

    版本 SpringBoot:2.7.3 Dubbo:3.0.4 Nacos:2.0.3 异常信息如下 Unable to make protected final java.lang.Class ja ...

  2. setup的执行时机

    setup是在beforeCreate之前执行的,也就是vue实例还未被创建,因为setup中并没有this指针 <script> export default { setup() { c ...

  3. MySQL 数据目录

    MySQL 的数据目录 1. MySQL 的主要目录结构 方式1:通过命令搜索 find / -name mysql 方式2(推荐):通过查看配置文件获取目录结构 vim /etc/my.cnf (重 ...

  4. postman——token传参

    问题描述: 有一个登陆接口获取token,其他接口再次访问都要带上token 解决方案: 1.在登陆接口访问后设置Postman的环境变量(Environment),例如设置环境变量名:token,值 ...

  5. Kotlin委托属性(1)

    在Kotlin中,委托属性(Delegated Properties)是一种强大的语言特性,允许你将属性的 getter 和 setter 方法的实现委托给其他对象.这使得你能够通过委托来重用代码.将 ...

  6. 3.CRUD及批量操作

    文档的CRUD index 和 create 操作用put(但是如果没有指定id必须用post,指定了id的可以用post,也可以用put) update和创建索引用post 获取用get 删除用de ...

  7. zabbix+oracle环境部署

    oracle11安装完成后, 实例名: zbx01 oracle创建zbx01用户:col file_name for a60;set linesize 160;select file_name,ta ...

  8. Redis 的主从复制

    Redis 主从复制是指:将一台 Redis 服务器的数据复制到其它的 Redis 服务器,前者所在的 Redis 服务器也被称为 "主节点"(Master / Leader),后 ...

  9. MyBatis中使用#{}和${}占位符传递参数的各种报错信息处理

    在Mapper层使@Select注解进行SQL语句查询时,往往需要进行参数传入和拼接,一般情况下使用两种占位符#{参数名}和${参数名},两者的区别为: 一.两种占位符的区别 1.参数传入方式的区别 ...

  10. 如何保证XML正确性

    如何保证XML正确性 XML是个盒子,什么都能装,但是装进去的东西正确与否恐怕无法得知.往往我们都人工审核.双人复核保证,但是次数多了难免会出错.那么我们如何保证和避免这种问题出现呢? 那就是XSD, ...