背景描述

在使用Docker时,启用centos7默认的firewall,启动端口映射时,防火墙规则不生效。docker默认使用了iptables防火墙机制。所以需要关闭firewall使用iptables解决。

1.关闭默认的firewall防火墙

systemctl stop firewalld.service 关闭防火墙
systemctl disable firewalld.service 关闭开机启动

  

2.开启iptables

yum install iptables (根据centOS7的版本和内核,有些版本已经装过,可以跳过此命令)
yum install iptables-services
service iptables restart
chkconfig iptables on或者systemctl enable iptables.service开机自启

  

3.编辑防火墙文件(开启了21,22,80,3306端口)

vim /etc/sysconfig/iptables

# sampleconfiguration for iptables service
# # you can edit thismanually or use system-config-firewall
# # please do not askus to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

  

4.添加防火墙命令

/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT

5.查看本机关于IPTABLES的设置情况

iptables -L -n

  

CentOS7中关闭firewall,并使用iptables管理防火墙的更多相关文章

  1. [CENTOS7] [IPTABLES] 卸载Firewall Id安装 IPTABLES及防火墙设置

    卸载Firewall ID,重装IPTABLES:先停止服务 systemctl stop firewalldsystemctl mask firewalld   yum install iptabl ...

  2. 003 centos7中关闭防火墙

    在centos7中,防火墙有了新的变化.下面是常用的几个命令. 1.查看状态 systemctl status firewalld 2.关闭防火墙 systemctl stop firewalld.s ...

  3. CentOS7.4 关闭firewall防火墙,改用iptables

    1.关闭默认的firewall防火墙 systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service ...

  4. centOS7中Mariadb数据库安装与基本管理

    一.Mariadb数据库安装 1. 直接yum源安装 yum -y install mariadb mariadb-serversystemctl start mariadb /启动Mariadb服务 ...

  5. CentOS7中关闭selinux

    在安装Cobbler和Puppet时需要关闭selinux,但是通常情况下载安装完CentOS7后,默认情况下SElinux是启用状态, 如下所示: [csharp] view plaincopy   ...

  6. CentOS7/6 关闭防火墙

    CentOS6关闭防火墙使用以下命令, //临时关闭 service iptables stop //禁止开机启动 chkconfig iptables off CentOS7中若使用同样的命令会报错 ...

  7. centos7 关闭firewall安装iptables并配置

    一.配置防火墙,开启80端口.3306端口 CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop fi ...

  8. centos7关闭默认firewall,启用iptables

    CentOS 7.0默认使用"firewall"防火墙 一:关闭firewall1.直接关闭防火墙systemctl stop firewalld.service 2.禁止fire ...

  9. CentOS7中firewall防火墙详解和配置,.xml服务配置详解

    修改防火墙配置文件之前,需要对之前防火墙做好备份 重启防火墙后,需要确认防火墙状态和防火墙规则是否加载,若重启失败或规则加载失败,则所有请求都会被防火墙 1. firewall-cmd --state ...

随机推荐

  1. 如何实现dede首页栏目文章指定调用

    如何实现dede首页栏目文章指定调用,首页文章栏目指定ID调用 dobote | 浏览 11891 次 推荐于2016-05-20 10:53:26 最佳答案 {dede:arclist flag=' ...

  2. PhpStorm (强大的PHP开发环境)2017.2.4 附注册方法

    http://www.oyksoft.com/soft/40722.html?pc=1 最新版PhpStorm 2017正式版改进了PHP 7支持,改进代码完成功能. PhpStorm 是最好的PHP ...

  3. LAMP和LNMP,你更愿意选择谁,为什么?

    https://www.zhihu.com/question/19697826 http://www.simongong.net lamp 的全称是linux + apache + mysql +ph ...

  4. 如何使用mysql命令行

    现在向大家介绍mysql命令行下,从数据库的建立到表数据的删除全过程,希望对网友有所帮助 方法/步骤 1.登陆mysql 打cmd命令终端,如果已经添加了mysql的环境变量,可以直接使用命令 mys ...

  5. PID算法笔记2

    总所周知,PID算法是个很经典的东西.而做自平衡小车,飞行器PID是一个必须翻过的坎.因此本节我们来好好讲解一下PID,根据我在学习中的体会,力求通俗易懂.并举出PID的形象例子来帮助理解PID.一. ...

  6. Node.js之单利模式

    在iOS中我们经常用到单利模式,这样就能够实现在多处共享同一数据,那么在Node.js中也存在这种模式. 我们知道,Node.js中模块的概念很重要,在写模块的接口的时候,只需要暴露出一个实例对象就能 ...

  7. C# 值类型,引用类型区别

    值类型/引用类型 作为所有类型的基类,System.Object提供了一组方法,这些方法在所有类型中都能找到,其中包含toString方法及clone等方法. 引用类型和值类型都继承自System.O ...

  8. awk批量处理文件夹中所有文件

       #c=``     done

  9. java foreach遍历的前提条件

    自我总结,欢迎拍砖,不胜感激! 目的: 加深foreach遍历的影响 证明:foreach遍历的前提条件是:list !=null ,而不是:list !=null && list.s ...

  10. linux配置上网

    重装系统之后,配置虚拟机的网络问题花了我三个小时,忘记了网关是vmnet8的IP还是DNS了,搞了很久,后来碰运气碰对了. 寄宿机共享的网络是vmnet8,设置IP,DNS,是vmnet8 的IPv4 ...