1、CentOS7默认的防火墙不是iptables,而是firewalle。

  关闭防火墙 systemctl stop firewalld
  启用防火墙 systemctl start firewalld
  禁用防火墙 systemctl mask firewalld
  禁止firewall开机启动 systemctl disable firewalld.service
  firewalld的规则配置文件:/etc/firewalld/zones/public.xml

  允许14.129.321.143这个ip访问6379端口
  <rule family="ipv4">
      <source address="14.129.321.143"/>
      <port protocol="tcp" port="6379"/>
      <accept/>
  </rule>
  配置规则都是用的xml格式,有点复杂。

2、以下是安装iptables的过程:

  你可以用rpm -qa | grep iptables来查看,一般会出现两个一个是iptables 另一个是iptables.service 安装方式如下
  安装iptable iptable-service
  #先检查是否安装了iptables
    service iptables status
  #安装iptables
    yum install -y iptables
  #升级iptables
    yum update iptables
  #安装iptables-services
    yum install iptables-services

开启iptables服务
#设置开机启动
  systemctl enable iptables.service
#开启服务
  systemctl start iptables.service
#查看状态
  systemctl status iptables.service

设置现有规则

#查看iptables现有规则
iptables -L -n
#先允许所有,不然有可能会杯具
iptables -P INPUT ACCEPT
#清空所有默认规则
iptables -F
#清空所有自定义规则
iptables -X
#所有计数器归0
iptables -Z
#允许来自于lo接口的数据包(本地访问)
iptables -A INPUT -i lo -j ACCEPT
#开放22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#开放21端口(FTP)
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
#开放80端口(HTTP)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
#开放443端口(HTTPS)
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
#允许ping
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
#允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
iptables -A INPUT -m state --state  RELATED,ESTABLISHED -j ACCEPT
#其他入站一律丢弃
iptables -P INPUT DROP
#所有出站一律绿灯
iptables -P OUTPUT ACCEPT
#所有转发一律丢弃
iptables -P FORWARD DROP

其他规则设定

#如果要添加内网ip信任(接受其所有TCP请求)
iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT
#过滤所有非以上规则的请求
iptables -P INPUT DROP
#要封停一个IP,使用下面这条命令:
iptables -I INPUT -s ***.***.***.*** -j DROP
#要解封一个IP,使用下面这条命令:
iptables -D INPUT -s ***.***.***.*** -j DROP

保存规则设定

#保存上述规则
service iptables save

解决vsftpd在iptables开启后,无法使用被动模式的问题

1.首先在/etc/sysconfig/iptables-config中修改或者添加以下内容

#添加以下内容,注意顺序不能调换
IPTABLES_MODULES="ip_conntrack_ftp"
IPTABLES_MODULES="ip_nat_ftp"

2.重新设置iptables设置

iptables -A INPUT -m state --state  RELATED,ESTABLISHED -j ACCEPT

 

centos----------防火墙firewalld和iptables的更多相关文章

  1. centos防火墙操作

    centos防火墙基本操作 #/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT#/sbin/iptables -I INPUT -p tcp -- ...

  2. 防火墙firewalld的基础操作

    防火墙Firewalld.iptables 1.systemctl模式 systemctl status firewalld #查看状态 2 systemctl start firewalld #启动 ...

  3. centos 防火墙 iptables firewalld SELinux

    参考 Centos7 只启用iptables 禁用firewalld功能 java.net.NoRouteToHostException: 没有到主机的路由 相关内容 centos7 中才开始引用fi ...

  4. CentOS7 防火墙firewalld 和 CentOS6 防火墙iptables 开放zabbix-agent端口的方法

    我们在生产环境中,一般都是把防火墙打开的,不像测试环境,可以直接关闭掉.最近安装zabbix ,由于公司服务器既有centos 7又有centos 6,遇到了一些防火墙的问题,现在正好把centos防 ...

  5. CentOS防火墙iptables的配置方法详解

    CentOS系统也是基于linux中的它的防火墙其实就是iptables了,下面我来介绍在CentOS防火墙iptables的配置教程,希望此教程对各位朋友会有所帮助. iptables是与Linux ...

  6. Centos 7防火墙firewalld开放80端口(转)

    开启80端口 firewall-cmd --zone=public --add-port=80/tcp --permanent 出现success表明添加成功 命令含义: --zone #作用域 -- ...

  7. CentOS 7 服务器配置--配置iptables防火墙

    #检查服务器是否安装了iptables systemctl status iptables.service #安装iptables yum install -y iptables #更新iptable ...

  8. CentOS 使用firewalld打开防火墙与端口

    CentOS 使用firewalld打开防火墙与端口 LinuxCentOS 基本使用 启动 : systemctl start firewalld 关闭 : systemctl stop firew ...

  9. CentOS之——CentOS7安装iptables防火墙

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761 CentOS7默认的防火墙不是iptables,而是firewall ...

  10. linux设置iptables防火墙的详细步骤(centos防火墙设置方法)

    CentOS系统也是基于linux中的它的防火墙其实就是iptables了,下面我来介绍在CentOS防火墙iptables的配置教程,希望此教程对各位朋友会有所帮助.   iptables是与Lin ...

随机推荐

  1. Linux中rz和sz命令用法详解

    http://www.111cn.net/sys/linux/67810.htm 在linux中rz 和 sz 命令允许开发板与主机通过串口进行传递文件了,下面我们就来简单的介绍一下rz 和 sz 命 ...

  2. c++的类的封装/继承/多态的简单介绍

    本篇文章仅仅从很表层来介绍一个C++语言中的类,包括什么是类,类的封装性/继承性和多态性.高手直接跳过吧,看了浪费时间,新手或者想温习一下的可以浏览看看. 1. 什么是类? 到底什么是类(class) ...

  3. 内建模块collections的使用

    # -*-coding:utf-8 -*- from collections import namedtuple Point=namedtuple('Point',['x','y']) p=Point ...

  4. python让实例作用于for循环并当做list来使用

    python如果想让一个类被用于for....in  循环,类型list和tuple那样,可以实现__iter__方法. 这个方法返回一个迭代对象,python的for循环就会不断调用该迭代对象的ne ...

  5. 使用Docker的macvlan为容器提供桥接网络及跨主机通讯

    对于了解Docker容器网络的朋友,我想对虚拟机的网络也不会陌生,毕竟我们是跟随这个时代一起学习和进步的人.相比VM,Docker的网络也在逐步走向成熟,本文主要针对其中的macvlan做下简单的介绍 ...

  6. 深度解剖session运行原理

    已经大半年没有更新博客了,一方面有比博客更重要的事情要做,另外一方面也没有时间来整理知识,所以希望在接下来的日子里面能够多多的写博客来与大家交流 什么是session session的官方定义是:Se ...

  7. Oracle 11gR2(11.2.0.4)安装包(7个)作用说明

    在之前使用Oracle10G的时候,官网下载的数据库安装包只有两个文件,解压合并后为完整的安装包. 后来因为检查出多个Oracle漏洞,需要现场Oracle数据库版本需要升级到11.2.0.4,下载的 ...

  8. numpy和tensorflow中的广播机制

    广播的引出 numpy两个数组的相加.相减以及相乘都是对应元素之间的操作. import numpy as np x = np.array([[2,2,3],[1,2,3]]) y = np.arra ...

  9. python数据分析及展示(三)

    一.Pandas库入门 1. Pandas库的介绍 http://pandas.pydata.org Pandas是Python第三方库,提供高性能易用数据类型和分析工具 import pandas ...

  10. 合并两个git仓库并保留提交记录

    case如下: 有2个git仓库:repo1.repo2: 想将repo1中的文件移入repo2: repo1的历史日志要保留:   1 2 # 1.将repo1作为远程仓库,添加到repo2中,设置 ...