CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤:

  1.先检查是否安装了: iptables service iptables status

  2.安装iptables: yum install -y iptables

  3.升级iptables(安装的最新版本则不需要): yum update iptables

  4.安装iptables-services: yum install iptables-services

  5.禁用/停止自带的firewalld服务

      (1).查看firewalld运行状态: systemctl start firewalld

      (2).停止firewalld服务: systemctl stop firewalld

      (3).禁用firewalld服务 systemctl mask firewalld

  6.设置现有规则

      (1).查看iptables现有规则: iptables -L -n

      (2).先允许所有,不然有可能会杯具: iptables -P INPUT ACCEPT

      (3).清空所有默认规则 iptables -F

      (4).清空所有自定义规则 iptables -X

      (5).所有计数器归0 iptables -Z

      (6).允许来自于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

      允许pingiptables -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

  7.保存规则设定,将会在/etc/sysconfig/路径下生产iptables文件。

    保存上述规则: service iptables save

  8.开启iptables服务

    (1).注册iptables服务,相当于以前的chkconfig: iptables on
systemctl enable iptables.service

    (2).开启服务
systemctl start iptables.service

    (3).查看状态
systemctl status iptables.service

参考iptables完整配置如下:

/**********下面是systemctl的一些命令*******************************/

        观察iptables和firewalld使用的两组命令,发现三个常用的命令:service、chkconfig、systemctl。

        systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起。

任务:

旧指令:

新指令:

1.使某服务自动启动

  chkconfig --level 3 httpd on

  systemctl enable httpd.service

2.使某服务不自动启动

  chkconfig --level 3 httpd off

  systemctl disable httpd.service

3.检查服务状态

  service httpd status

  systemctl status httpd.service(服务详细信息) 

  systemctl is-active httpd.service(仅显示是否 Active)

4.显示所有已启动的服务

  chkconfig --list

  systemctl list-units --type=service

5.启动某服务

  service httpd start

  systemctl start httpd.service

6.停止某服务

  service httpd stop

  systemctl stop httpd.service

7.重启某服务

  service httpd restart

  systemctl restart httpd.service

CentOS 7.0 firewall防火墙关闭firewall作为防火墙,这里改为iptables防火墙的更多相关文章

  1. CentOS 7中firewall防火墙详解和配置以及切换为iptables防火墙

    官方文档介绍地址: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Gui ...

  2. CentOS 7.4中firewall防火墙详解和配置以及切换为iptables防火墙

    转载:https://blog.csdn.net/xlgen157387/article/details/52672988 一.firewall介绍 CentOS 7中防火墙是一个非常的强大的功能,在 ...

  3. CentOS 7中firewall防火墙详解和配置以及切换为iptables防火墙--转载

    最近在linux(这里用到的是Centos7的64位版本)安装nginx时,在开放80端口时用iptables设置端口 和重启服务发现提示未找到文件,在网络上收集查找后发现在Centos7中iptab ...

  4. Ubuntu使用iptables配置防火墙提示:unrecognized service(Ubuntu配置iptables防火墙)

    Ubuntu默认安装是没有开启任何防火墙的. 当使用service iptables status时发现提示iptables:unrecoginzed service.意思是无法识别的服务. 以下方法 ...

  5. CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。

    firewall:systemctl start firewalld.service#启动firewallsystemctl stop firewalld.service#停止firewallsyst ...

  6. CentOS 7.0关闭默认firewall防火墙启用iptables防火墙

    操作系统环境:CentOS Linux release 7.0.1406(Core) 64位CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤. 1.关闭f ...

  7. Linux学习之八--关闭firewall防火墙安装iptables并配置

    CentOS 7之后默认使用的是firewall作为防火墙,这里改为iptables防火墙,并开启80端口.3306端口. 1.关闭firewall: systemctl stop firewalld ...

  8. CentOS 7.0,启用iptables防火墙

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

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

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

随机推荐

  1. python爬虫24 | 搞事情了,用 Appium 爬取你的微信朋友圈。

    昨天小帅b看到一些事情不顺眼 有人偷换概念 忍不住就写了一篇反讽 996 的 看不下去了,我支持996,年轻人就该996! 没想到有些人看不懂 这就算了 还来骂我 早些时候关注我的小伙伴应该知道我第一 ...

  2. importdata-- matlab

    source file: test.dat *************************** Day1  Day2  Day3  Day4  Day5  Day6  Day795.01 76.2 ...

  3. How to read and write multiple files in Python?

    Goal: I want to write a program for this: In a folder I have =n= number of files; first read one fil ...

  4. noip模拟赛 天天寄快递

    分析:并不是特别难的一道题,用到了贪心算法. 首先可以明确的一点是我们要尽量偷贡献最大的数据,要先满足每一个公司的贡献都大于等于K,以这个作为首要条件.那么我们可以先把每个快递公司的快递按照贡献从大到 ...

  5. CODEVS1022 覆盖 (二分图染色+匈牙利算法)

    先对整幅图进行二分图染色,再跑一遍匈牙利算法. /* CODEVS1022 */ #include <cstdio> #include <cstring> #include & ...

  6. spring-boot-starter-actuator(健康监控)配置和使用

    在生产环境中,需要实时或定期监控服务的可用性.Spring Boot的actuator(健康监控)功能提供了很多监控所需的接口,可以对应用系统进行配置查看.相关功能统计等. 集成: <depen ...

  7. SVN提交时报错:Commit blocked by pre-commit hook (exit code 1) with no output.

    可能的原因: 提交代码的SVN命令中,Comment长度短了.参考:http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-howto-minl ...

  8. [Mini Programe] Upload Images

    Code for upload iamges: chooseImage: choose the images to upload previewImage: preview the image and ...

  9. 改动wordpress默认发邮件邮箱地址

    方法一: wordpress发送邮件默认是用的php mail函数.所以发送邮件的地址是能够随意写的.其默认发邮件的地址是wordpress@yourdomain.com.当然这个地址是能够改动的. ...

  10. POJ_1679_The Unique MST(次小生成树模板)

    The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23942   Accepted: 8492 D ...