转载请注明出处:http://blog.csdn.net/l1028386804/article/details/50779761

CentOS7默认的防火墙不是iptables,而是firewalle.

安装iptable iptable-service

  1. #先检查是否安装了iptables
  2. service iptables status
  3. #安装iptables
  4. yum install -y iptables
  5. #升级iptables
  6. yum update iptables
  7. #安装iptables-services
  8. yum install iptables-services
#先检查是否安装了iptables
service iptables status
#安装iptables
yum install -y iptables
#升级iptables
yum update iptables
#安装iptables-services
yum install iptables-services

禁用/停止自带的firewalld服务

  1. #停止firewalld服务
  2. systemctl stop firewalld
  3. #禁用firewalld服务
  4. systemctl mask firewalld
#停止firewalld服务
systemctl stop firewalld
#禁用firewalld服务
systemctl mask firewalld

设置现有规则

  1. #查看iptables现有规则
  2. iptables -L -n
  3. #先允许所有,不然有可能会杯具
  4. iptables -P INPUT ACCEPT
  5. #清空所有默认规则
  6. iptables -F
  7. #清空所有自定义规则
  8. iptables -X
  9. #所有计数器归0
  10. iptables -Z
  11. #允许来自于lo接口的数据包(本地访问)
  12. iptables -A INPUT -i lo -j ACCEPT
  13. #开放22端口
  14. iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  15. #开放21端口(FTP)
  16. iptables -A INPUT -p tcp --dport 21 -j ACCEPT
  17. #开放80端口(HTTP)
  18. iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  19. #开放443端口(HTTPS)
  20. iptables -A INPUT -p tcp --dport 443 -j ACCEPT
  21. #允许ping
  22. iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
  23. #允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
  24. iptables -A INPUT -m state --state  RELATED,ESTABLISHED -j ACCEPT
  25. #其他入站一律丢弃
  26. iptables -P INPUT DROP
  27. #所有出站一律绿灯
  28. iptables -P OUTPUT ACCEPT
  29. #所有转发一律丢弃
  30. iptables -P FORWARD DROP
#查看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

其他规则设定

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

保存规则设定

  1. #保存上述规则
  2. service iptables save
#保存上述规则
service iptables save

开启iptables服务

  1. #注册iptables服务
  2. #相当于以前的chkconfig iptables on
  3. systemctl enable iptables.service
  4. #开启服务
  5. systemctl start iptables.service
  6. #查看状态
  7. systemctl status iptables.service
#注册iptables服务
#相当于以前的chkconfig iptables on
systemctl enable iptables.service
#开启服务
systemctl start iptables.service
#查看状态
systemctl status iptables.service

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

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

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

2.重新设置iptables设置

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

以下为完整设置脚本

    1. #!/bin/sh
    2. iptables -P INPUT ACCEPT
    3. iptables -F
    4. iptables -X
    5. iptables -Z
    6. iptables -A INPUT -i lo -j ACCEPT
    7. iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    8. iptables -A INPUT -p tcp --dport 21 -j ACCEPT
    9. iptables -A INPUT -p tcp --dport 80 -j ACCEPT
    10. iptables -A INPUT -p tcp --dport 443 -j ACCEPT
    11. iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
    12. iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
    13. iptables -P INPUT DROP
    14. iptables -P OUTPUT ACCEPT
    15. iptables -P FORWARD DROP
    16. service iptables save
    17. systemctl restart iptables.service

CentOS之——CentOS7安装iptables防火墙的更多相关文章

  1. CentOS7安装iptables防火墙

    CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...

  2. Centos7下安装iptables防火墙

    说明:centos7默认使用的firewalld防火墙,由于习惯使用iptables做防火墙,所以在安装好centos7系统后,会将默认的firewall关闭,并另安装iptables进行防火墙规则设 ...

  3. CentOS 7.0启用iptables防火墙

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙. 1.关闭firewall: systemctl stop firewalld.service #停止fir ...

  4. CentOs7 使用iptables防火墙开启关闭端口

    CentOs7 使用iptables防火墙开启关闭端口   # 0x01介绍 iptables命令是Linux上常用的防火墙软件,是netfilter项目的一部分iptables文件设置路径:命令:v ...

  5. centos 7 安装iptables防火墙

    firewalle: 开启6379端口和16379端口 [root@localhost ~]# firewall-cmd --zone=public --add-port=6379/tcp --per ...

  6. Centos安装iptables防火墙

    一.安装说明: 1.因为centos7.0及以上版本就默认安装了firewall防火墙,但有时候根据项目实际所需,服务器上还是需要安装iptables,以下就是具体的安装步骤: 2.因阿里云在服务器外 ...

  7. CentOS7使用iptables防火墙开放端口

    背景:在CentOS上面安装了mysql.svn.tomcat等软件,发现访问不了,用telnet命令查看端口,发现都不通: telnet IP 端口 CentOS7 默认使用firewalld防火墙 ...

  8. entOS7安装iptables防火墙,试验未通过

    CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...

  9. CentOS7配置iptables防火墙

    CentOS 7中默认是firewalld防火墙,如果使用iptables需要先关闭firewalld防火墙(1.关闭防火墙,2.取消开机启动). #关闭firewalld systemctl sto ...

随机推荐

  1. 进程池pool

    如果有多个进程,同一时间只能有限个给cpu运行 from multiprocessing import Process,Pool import time,os def bar(arg): print( ...

  2. oracle--合并行数据(拼接字符串),获取查询数据的前3条数据...

    --标准函数Lpad 可以实现左补零,但是如果多于需要长度,则会截断字符串 SELECT LPAD ('1' , 3 , '0') FROM DUAL -- return 001 情况一:需要补零.  ...

  3. php 测试 程序执行时间,内存使用情况

    memory_get_usage 可以分析内存占用空间. microtime 函数就可以分析程序执行时间. 上栗子: echo '开始内存:'.memory_get_usage(), ''; $tmp ...

  4. workerman vmstat服务器状态监控服务

    转载出自 :http://www.workerman.net/workerman-vmstat workerman vmstat服务器状态监控服务 vmstat 命令可以展现服务器的CPU使用率,内存 ...

  5. 用Matlab进行部分分式展开

    [r p k]=residue[num,den] 例如H(s)=(2s3+5s2+3s+6)/(s3+6s2+11s+6) num=[2 5 3 6]; den=[1 6 11 6]; [r p k] ...

  6. Python中的self和init

    From: https://www.crifan.com/summary_the_meaning_of_self_and___init___in_python_and_why_need_them/ 背 ...

  7. SpringSecurity的Filter执行顺序在源码中的体现

    在网上看各种SpringSecurity教程时,都讲到了SpringSecurity的Filter顺序.但是一直不知道这个顺序在源码中是如何体现的.今天一步一步的查找,最终找到顺序是在FilterCo ...

  8. Qt学习——QListWidget控件的使用

    转载:GDUTLYP Qt提供QListWidget类列表框控件用来加载并显示多个列表项.QListWidgetItem类就是列表项类. 一般列表框控件中的列表项有两种加载方式: 一种是由用户手动添加 ...

  9. Python error: Microsoft Visual C++ 9.0 is required 解决方案

    换了新电脑,在使用python2.7 pip 安装ipython时,报错了 error: Microsoft Visual C++ 9.0 is required. Get it from http: ...

  10. ubuntu安装最新的mercurial

    Mercurial 是一种轻量级分布式版本控制系统,采用 Python 语言实现,易于学习和使用,扩展性强 之前安装的mercurial版本(2.8.2)太老了,想安装最新版本的. 网上搜到方法 su ...