docker、firewalld和iptables之间的关系

2023-05-16

要注意docker命令中使用 -p 暴露端口时,实现需要依赖iptables。CentOS 7默认使用的是firewalld,但是是否需要关闭firewalld并启动iptables呢?

参考多篇博文,答案应该是不不需要的。

Note. You need to distinguish between the iptables service and the iptables command. Although firewalld is a replacement for the firewall management provided by iptables service, it still uses the iptables command for dynamic communication with the kernel packet filter (netfilter). So it is only the iptables service that is replaced, not the iptables command. That can be a confusing distinction at first.

在实际使用过程中,没有使用iptables.service,docker的端口转发也是正常的,因为iptables一直都在。docker会创建自己的iptables链,如果firewalld重启,docker创建的链也需要重新创建。

下面是停用firewalld服务,启用iptables-services
#!/bin/sh

#停止firewalld服务
systemctl stop firewalld    
#禁用firewalld服务
systemctl mask firewalld

yum install -y iptables
yum update iptables
yum install -y iptables-services

systemctl enable iptables.service
systemctl start iptables.service

#暴露docker swarm需要的端口,如果不使用docker swarm不需要打开端口
iptables -A INPUT -p tcp --dport 2377 -j ACCEPT
iptables -A INPUT -p tcp --dport 7946 -j ACCEPT
iptables -A INPUT -p udp --dport 7946 -j ACCEPT
iptables -A INPUT -p tcp --dport 4789 -j ACCEPT
iptables -A INPUT -p udp --dport 4789 -j ACCEPT

service iptables save
systemctl restart iptables.service

#开启转发
echo 'net.ipv4.ip_forward=1'> /usr/lib/sysctl.d/00-system.conf

systemctl restart network

直接使用firewalld

sudo firewall-cmd --permanent --zone=trusted --add-interface=docker0
sudo firewall-cmd --permanent --zone=trusted --add-port=xxxx/tcp#       xxxx改为你希望的端口号
sudo firewall-cmd --reload



 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

docker、firewalld和iptables之间的关系 的相关文章

随机推荐

  • WIFI安全测试之WPS(PIN)加密暴力破解

    前言 无线AP的接入验证有很多种方式 xff0c 家用无线路由器的验证方式包括OPEN WEP WPA WPA2 xff0c WPS的出现降低了接入验证的复杂度 xff0c 但是这种方式却隐含带来许多问题 同时由于很早就入手了第一批WIFI
  • Arduino+蜂鸣器制作有趣的小音乐

    Arduino相关姿势 Arduino是一个开源的硬件平台 xff0c 包括开发套组 xff08 开发板和相关的模块以及连线 xff09 和IDE 开发语言基于C 核心是一块8位ATmega328的处理器 xff0c 这块处理器是AVR单片
  • 计算机图形学笔记

    前言 图形学还是相对比较重要的课程 xff0c 趁着刚刚学完简要记录一下 基本内容 基本几何元素及其表示 xff0c 点 线 面 环以及三维形体 一般的 xff0c 我们使用参数方程来表示一个几何元素 参数方程中未知数的个数为元素的维数 三
  • 深入理解Java中的String

    深入理解Java中的String 本篇转载自博客园 xff0c 原作者平凡希 xff0c 特此说明
  • 反爬虫

    反爬虫
  • 设计模式——生产消费者模式

    设计模式 生产消费者模式 生产者消费者问题是线程模型中的经典问题 xff1a 生产者和消费者在同一时间段内共用同一存储空间 xff0c 生产者向空间里生产数据 xff0c 而消费者取走数据 像图片下载加载的模型就可以参考这个模型 UML图
  • win10如何修改mac地址(亲测通过)

    1 查看现有的mac地址 步骤 xff1a 打开cmd界面 xff0c 输入ipconfig all按回车 如下图 xff0c 箭头所指即为当前mac地址 2 屏幕右下角右键点击网络图标 xff0c 见下图 打开网络和共享中心 xff0c
  • eclipse怎么恢复默认界面

    Eclipse里面将界面恢复到默认状态 xff1a 1 选择Eclipse的工具栏里面的 窗口 xff08 Window xff09 xff0c xff08 Window Perspective Reset Perspective xff0
  • fatal: Authentication failed could not read from remote repository

    Git 无法clone pull fetch 异常 xff1a fatal could span class hljs operator not span span class hljs built in read span span cl
  • Mybatis Plus 自定义方法实现分页

    一般物理分页 xff0c 即通过sql语句分页 xff0c 都是在sql语句后面添加limit分页语句 xff0c 在xml文件里传入分页的参数 xff0c 再多配置一条sql xff0c 用于查询总数 xff1a lt select id
  • mac远程桌面Microsoft Remote Desktop for Mac - Mac-连接Windows远程桌面

    好记星不如烂笔头 xff0c 这里记录平时工作中用到的东西 xff0c 不喜可以留言 1 xff1a 在mac电脑远程桌面可以使用 xff0c Microsoft 远程桌面 使用 Microsoft Remote Desktop 这个还是很
  • 安装gentoo的点点滴滴(三)

    1 每次启动电脑都不能启动swap分区 xff0c 都要用swapon dev sdb3来激活交换分区 再去看gentoo的安装手册 xff0c 原来是 etc fstab没有编辑好 xff0c 使用其自动生成的有问题 现在将自己修改的贴上
  • keil5 串口打印的实现

    目的 xff1a 在keil5中实现串口打印 xff0c debug信号 方法 xff1a 首先安装串口调试工具 添加 include lt stdio h gt 重定向fputc函数 xff1a int fputc int ch FILE
  • 在Ubuntu中使用apt-get的时候,始终显示“E:无法定位软件包”

    可能的一个原因是因为安装过后没有更新软件源 xff0c 试试用 sudo apt get update 命令更新一下软件源
  • Linux安装nginx启动时出错:error while loading shared libraries: libpcre.so.0: cannot open shared object file

    启动linux的时候出现 xff1a error while loading shared libraries libpcre so 0 cannot open shared object file 解决方法 xff1a 1 cd lib6
  • Ubuntu 安装Chrome

    去官网下载安装包 google chrome stable current amd64 deb 地址 https www google com intl zh CN chrome browser sudo dpkg i google chr
  • redis集群搭建过程中踩过的几个坑

    这两天在玩redis的集群 xff0c 搭建过程中遇到了以下几个问题 首先是redis ERR Not all 16384 slots are covered by nodes 不是所有的slot都被分配了 xff0c 可以考虑使用redi
  • 业务分析系列主题:业务场景

    本文介绍了了业务场景的概念 要素以及创建方法 xff0c 与大家分享 xff01 业务场景作为一种需求分析技术用途十分广泛 本文涛哥就和大家聊聊业务场景是什么 xff0c 以及如何创建业务场景 一 业务场景是什么 xff1f 所谓 场景 x
  • 业务分析主题系列:常见的业务场景

    常见的业务场景 场景1 xff1a 数据涨跌异常如何处理 xff1f 场景2 xff1a 如何评估渠道质量 xff0c 确定投放优先级 xff1f 场景3 xff1a 一个功能 内容上线后 xff0c 如何评估其价值 xff1f 场景4 x
  • docker、firewalld和iptables之间的关系

    要注意docker命令中使用 p 暴露端口时 xff0c 实现需要依赖iptables CentOS 7默认使用的是firewalld 但是是否需要关闭firewalld并启动iptables呢 xff1f 参考多篇博文 xff0c 答案应