前言:CentOS7 的防火墙默认使用是firewall,而我们通常使用iptables;

本文记录了firewall基础的命令和iptables的安装和使用。

firewall部分:

part1 : 服务命令

systemctl start firewalld#启动

systemctl status firewalld #查看运行状态

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁用:禁止firewall开机启动

firewall-cmd --state #

firewall-cmd--reload 重启

part2 : 端口命令:

添加

firewall-cmd --zone=public --add-port=80/tcp --permanent   (--permanent永久生效,没有此参数重启后失效)

重新载入

firewall-cmd --reload

查看

firewall-cmd --zone= public --query-port=80/tcp

删除

firewall-cmd --zone= public --remove-port=80/tcp --permanent

part3:示例

示例:firewall端口操作完之后需要重启服务生效

  1. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --query-port=3307/tcp
  2. no
  3. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --add-port=3307/tcp --permanent
  4. success
  5. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --query-port=3307/tcp
  6. no
  7. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --reload
  8. success
  9. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --query-port=3307/tcp
  10. yes

示例:mysql开放远程端口

  1. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
  2. success
  3. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --reload
  4. success
  5. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --state
  6. running
  7. [root@iZ2zeczh9tfpmxmijw5qppZ ~]#
  8. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# firewall-cmd --zone=public --query-port=3306/tcp
  9. yes
  10. [root@iZ2zeczh9tfpmxmijw5qppZ ~]#

iptables部分

part1 : 服务命令

systemctl start iptables #启动

systemctl status iptables #查看运行状态

systemctl restart iptables.service #停止iptables

systemctl stop iptables.service #停止iptables

systemctl disable iptables.service #禁用:禁止iptables开机启动

systemctl enable iptables.service #

part2 : 安装

step1 : 查看是否安装

  1. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl status iptables
  2. Unit iptables.service could not be found.
  3. [root@iZ2zeczh9tfpmxmijw5qppZ ~]#

没有相关服务

step2 : yum install

  1. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# yum install iptables-services
  2. Loaded plugins: fastestmirror
  3. base                                                                                                             | 3.6 kB  00:00:00
  4. epel                                                                                                             | 4.3 kB  00:00:00
  5. extras                                                                                                           | 3.4 kB  00:00:00
  6. mysql-connectors-community                                                                                       | 2.5 kB  00:00:00
  7. mysql-tools-community                                                                                            | 2.5 kB  00:00:00
  8. mysql56-community                                                                                                | 2.5 kB  00:00:00
  9. updates                                                                                                          | 3.4 kB  00:00:00
  10. updates/7/x86_64/primary_db                                                                                      | 6.4 MB  00:00:06
  11. Loading mirror speeds from cached hostfile
  12. * base: mirrors.aliyuncs.com
  13. * epel: mirrors.aliyuncs.com
  14. * extras: mirrors.aliyuncs.com
  15. * updates: mirrors.aliyuncs.com
  16. Resolving Dependencies
  17. --> Running transaction check
  18. ---> Package iptables-services.x86_64 0:1.4.21-17.el7 will be installed
  19. --> Finished Dependency Resolution
  20. Dependencies Resolved
  21. ========================================================================================================================================
  22. Package                                Arch                        Version                             Repository                 Size
  23. ========================================================================================================================================
  24. Installing:
  25. iptables-services                      x86_64                      1.4.21-17.el7                       base                       50 k
  26. Transaction Summary
  27. ========================================================================================================================================
  28. Install  1 Package
  29. Total download size: 50 k
  30. Installed size: 24 k
  31. Is this ok [y/d/N]: Y
  32. Downloading packages:
  33. iptables-services-1.4.21-17.el7.x86_64.rpm                                                                       |  50 kB  00:00:00
  34. Running transaction check
  35. Running transaction test
  36. Transaction test succeeded
  37. Running transaction
  38. Installing : iptables-services-1.4.21-17.el7.x86_64                                                                               1/1
  39. warning: /etc/sysconfig/iptables created as /etc/sysconfig/iptables.rpmnew
  40. Verifying  : iptables-services-1.4.21-17.el7.x86_64                                                                               1/1
  41. Installed:
  42. iptables-services.x86_64 0:1.4.21-17.el7
  43. Complete!
  44. [root@iZ2zeczh9tfpmxmijw5qppZ ~]#

安装成功!

step3 : check

  1. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl status iptables
  2. iptables.service - IPv4 firewall with iptables
  3. Loaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)
  4. Active: inactive (dead)
  5. [root@iZ2zeczh9tfpmxmijw5qppZ ~]#

step4 : start

  1. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl start iptables
  2. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl enable iptables.service
  3. Created symlink from /etc/systemd/system/basic.target.wants/iptables.service to /usr/lib/systemd/system/iptables.service.
  4. [root@iZ2zeczh9tfpmxmijw5qppZ ~]#
  1. [root@iZ2zeczh9tfpmxmijw5qppZ ~]# systemctl status iptables
  2. iptables.service - IPv4 firewall with iptables
  3. Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
  4. Active: active (exited) since Wed 2017-06-21 15:44:41 CST; 1min 17s ago
  5. Main PID: 506 (code=exited, status=0/SUCCESS)
  6. Jun 21 15:44:41 iZ2zeczh9tfpmxmijw5qppZ systemd[1]: Starting IPv4 firewall with iptables...
  7. Jun 21 15:44:41 iZ2zeczh9tfpmxmijw5qppZ iptables.init[506]: iptables: Applying firewall rules: [  OK  ]
  8. Jun 21 15:44:41 iZ2zeczh9tfpmxmijw5qppZ systemd[1]: Started IPv4 firewall with iptables.
  9. [root@iZ2zeczh9tfpmxmijw5qppZ ~]#

step5 : 修改配置文件

vi /etc/sysconfig/iptables

systemctl restart iptables.service #重启防火墙使配置生效

step6 : 关闭SELINUX

vi/etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存退出

setenforce 0 #使配置立即生效

备注:

SELINUX不关闭时,iptables不读取配置文件,一般采取关闭SELINUX的方式避免这种冲突

CentOS7的firewall和安装iptables的更多相关文章

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

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

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

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

  3. CentOS7将firewall切换为iptables防火墙

  4. CentOS7.3下的一个iptables配置

    centos7.3默认使用的防火墙应该是firewall,而不是iptables.而我们xxmj服务器使用的是iptables防火墙.所以,在配置防火墙之前,我们需要先关闭firewall,安装ipt ...

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

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

  6. Centos7下安装iptables防火墙

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

  7. CentOS7安装iptables防火墙

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

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

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

  9. centos7上安装iptables

    centos7上安装iptables的步骤 注意:CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #安装iptables ...

随机推荐

  1. BTC钱包对接流程

    BTC钱包对接流程: 部署钱包节点 分析钱包的API 通过JSON-RPC访问钱包API 部署测试 1.部署钱包节点 虚拟币交易平台对接所有的虚拟币之前,都要在自己的服务器上部署一个钱包节点,首先要找 ...

  2. shell 中的流程控制关键字

    if...else if [ $1x == "ab"x ]; then echo "you had enter ab" elif [ $1x == " ...

  3. shell参数代表什么,如何调试shell?

    $0就是该bash文件名$?是上一指令的返回值$*所有位置参数的内容:就是调用调用本bash shell的参数.$@基本上与上面相同.只不过是“$*”返回的是一个字符串,字符串中存在多外空格.“$@” ...

  4. python3 安装MySQLdb及无法打开mysql.h问题解决(win7 )

    在Flask中要连接mysql数据库,需要安装flask-mysqldb. pip install flask-mysqldb 用pip安装MySQLdb 中遇到如下问题,折腾半天之久,多方尝试,终搞 ...

  5. 服务器(Linux) 安装python3

    1.python3和python2可以共存,不用删自带的python2 服务器Linux下默认系统自带python2.6的版本,这个版本被系统很多程序所依赖,所以不建议删除.如果使用最新的Python ...

  6. P3866 [TJOI2009]战争游戏

    P3866 [TJOI2009]战争游戏 题目背景 小R正在玩一个战争游戏.游戏地图是一个M行N列的矩阵,每个格子可能是障碍物,也可能是空地,在游戏开始时有若干支敌军分散在不同的空地格子中.每支敌军都 ...

  7. python中的文件操作(2)

    a+,w+,r+的特点: r+:r+模式允许读和写,当对文件句柄只进行写操作时,tell(),seek()为写操作的‘指针’(也就是写到seek()处). 当只进行读操作时,tell(),seek() ...

  8. java基础-基本的输入与输出

    java基础-基本的输入与输出 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.基本的输出 基本的输出,System.out 就是系统的标准输出设备,默认为显示器. 1>. ...

  9. [洛谷P4491] [HAOI2018]染色

    洛谷题目链接:[HAOI2018]染色 题目背景 HAOI2018 Round2 第二题 题目描述 为了报答小 C 的苹果, 小 G 打算送给热爱美术的小 C 一块画布, 这块画布可 以抽象为一个长度 ...

  10. java并发实践笔记

    底层的并发功能与并发语义不存在一一对应的关系.同步和条件等底层机制在实现应用层协议与策略须始终保持一致.(需要设计级别策略.----底层机制与设计级策略不一致问题). 简介 1.并发简史.(资源利用率 ...