Centos系统防火墙介绍

概述:
  1.Filewalld(动态防火墙)作为redhat7系统中变更对于netfilter内核模块的管理工具;
  2.iptables service 管理防火墙规则的模式(静态):用户将新的防火墙规则添加进 /etc/sysconfig/iptables 配置文件当中,再执行命令 /etc/init.d/iptables reload 使变更的规则生效。在这整个过程的背后,iptables service 首先对旧的防火墙规则进行了清空,然后重新完整地加载所有新的防火墙规则,如果加载了防火墙的模块,需要在重新加载后进行手动加载防火墙的模块;
  3.firewalld 管理防火墙规则的模式(动态):任何规则的变更都不需要对整个防火墙规则列表进行重新加载,只需要将变更部分保存并更新到运行中的 iptables 即可;还有命令行和图形界面配置工具,它仅仅是替代了 iptables service 部分,其底层还是使用 iptables 作为防火墙规则管理入口。

  Centos7以前的系统版本默认使用iptables服务来管理防火墙,Centos7系统及以后使用firewalld服务替代了iptables服务,但是依然可以使用iptables来管理内核的netfilter。其实iptables服务和firewalld服务都不是真正的防火墙,只是用来定义防火墙规则功能的管理工具,将定义好的规则交由内核中的netfilter(网络过滤器来读取)从而实现真正的防火墙功能。

  参考:https://blog.csdn.net/xiazichenxi/article/details/80169927

FireWalld服务

介绍:

  1. 工具名称:firewalld
  2. firewalld的服务名称:firewalld
  3. firewalld的操作工具:firewall-cmd

使用:

1.安装firewalld:

  1. yum -y install firewalld
  2. #需要安装图形化界面时,安装firewalld-config
  3. yum -y install firewalld-config

2.配置开机启动:

  1. #开机启动
  2. systemctl enable firewalld
  3. #禁止启动
  4. systemctl disable firewalld

3.启动firewalld:

  1. #启动firewalld
  2. systemctl start firewalld
  3. #停止firewalld
  4. systemctl stop firewalld
  5. #重启firewalld
  6. systemctl restart firewalld

4.配置文件

  1. #直接修改配置文件
  2. /lib/firewalld/ 用于默认和备用配置
  3. /etc/firewalld/ 用于用户创建和自定义配置文件 覆盖默认配置
  4. /etc/firewalld/firewall.conf 全局配置

Firewall-Cmd常用命令

  1. #帮助命令
  2. firewall-cmd --version 查看firewalld版本
  3. firewall-cmd --help 查看firewall-cmd用法
  4. man firewall-cmd
  5.  
  6. #查看状态
  7. firewall-cmd --state #查看firewalld的状态
  8. systemctl status firewalld #查看firewalld的状态,详细

  9. firewall-cmd --reload 重新载入防火墙配置,当前连接不中断
  10. firewall-cmd --complete-reload 重新载入防火墙配置,当前连接中断
  11.  
  12. #添加服务或者端口
  13. firewall-cmd --get-services 列出所有预设服务
  14. firewall-cmd --list-services 列出当前服务
  15. firewall-cmd --permanent --zone=public --add-service=smtp 启用服务
  16. firewall-cmd --permanent --zone=public --remove-service=smtp 禁用服务
  17. firewall-cmd --zone=public --list-ports
  18. firewall-cmd --permanent --zone=public --add-port=8080/tcp 启用端口, --permanent 表示永久有效的配置, --zone表示配置的是公共区域
  19. firewall-cmd --permanent --zone=public --remove-port=8080/tcp 禁用端口
  1. 运行时配置和永久配置
    firewall-cmd zone=public add-service=smtp 运行时配置,重启后失效
    firewall-cmd permanent zone=public add-service=smtp 永久配置,不影响当前连接,重启后生效
    firewall-cmd runtime-to-permanent 将运行时配置保存为永久配置
  2.  
  3. #区域命令
  4. firewall-cmd --get-zones 查看所有可用区域
  5. firewall-cmd --get-active-zones 查看当前活动的区域,并附带一个目前分配给它们的接口列表
  6. firewall-cmd --list-all-zones 列出所有区域的所有配置
  7. firewall-cmd --zone=work --list-all 列出指定域的所有配置
  8. firewall-cmd --get-default-zone 查看默认区域
  9. firewall-cmd --set-default-zone=public 设定默认区域

Iptables服务

如果想使用iptables配置防火墙规则,要先安装iptables并禁用firewalld

  1. 1.安装iptables
  2. yum install iptables-services
  3.  
  4. 2.配置文件路径:
  5. /etc/sysconfig/iptables
  6.  
  7. 3.查看防火墙开启的端口详情列表:
  8. iptables -vnL
  9.  
  10. 4.重启iptables
  11. service iptables restart
  12. #重启防火墙使配置文件生效
  13. systemctl restart iptables.service
  14.  
  15. 5.关闭iptables
  16. service iptables stop
  17. systemctl stop iptables.service
  18.  
  19. 6.设置iptables防火墙为开机启动项
  20. systemctl enable iptables.service
  21. systemctl disable iptables.service
  22. 开机启动方式:
  23. vi /etc/rc.local
  24. 添加命令: iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
  25.  
  26. 7.添加开放端口
  27. 配置文件[/etc/sysconfig/iptables]开启端口:
  28. -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
  29. 添加803306端口
  30. -A INPUT -m state state NEW -m tcp -p tcp dport 80 -j ACCEPT
  31. -A INPUT -m state state NEW -m tcp -p tcp dport 3306 -j ACCEPT
  32.  
  33. 动态命令开启端口:
  34. iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

  

Centos 的防火墙(firewalld,iptables)的更多相关文章

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

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

  2. Linux Centos 开启防火墙 FirewallD is not running

    转载自:http://www.z4zr.com/page/1006.html CentOS7用firewall命令“替代”了iptables.在这里我们需要区分“iptables服务”和“iptabl ...

  3. 腾讯云服务器CentOS 7防火墙firewalld管理

    在腾讯云上买了个服务器(centOS7),部署了Tomcat(8080),Apache(80),MySQL(3306)等,一开始按照百度教程配置是把防火墙关闭了的.最近一段时间服务器总是莫名的被人修改 ...

  4. Linux centos修改防火墙为iptables

    防火墙配置 CentOS 7默认使用的是firewall作为防火墙,这里改为iptables防火墙.  firewall操作: # service firewalld status; #查看防火墙状态 ...

  5. (9)centos下防火墙firewalld设置

    学习apache安装的时候需要打开80端口,由于centos 7版本以后默认使用firewalld后,网上关于iptables的设置方法已经不管用了,想着反正iptable也不会用,索性直接搬官方文档 ...

  6. Centos 7 防火墙firewalld命令

    今天自己在Hyper-v下搭建三台Linux服务器集群,用于学习ELKstack(即大数据日志解决技术栈Elasticsearch,Logstash,Kibana的简称),下载的Linux版本为cen ...

  7. Centos 7防火墙firewalld开放80端口

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

  8. Centos 7 防火墙 firewalld 简单使用说明

    1.firewalld简介 firewalld是centos7的一大特性,最大的好处有两个:支持动态更新,不用重启服务:第二个就是加入了防火墙的“zone”概念   2.firewalld命令行界面管 ...

  9. Centos 7防火墙firewalld开放端口

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

随机推荐

  1. [CSP-S模拟测试]:f(Trie树+二分答案+meet in middle+two pointers)

    题目传送门(内部题67) 输入格式 第一行,三个整数$n$.$k$.$p$.第二行,$n$个自然数,表示$\{a_i\}$. 输出格式 输出一行,两个自然数,表示$f(res)$.$res$. 样例 ...

  2. shell scripts 编写基础

    一.shell变量的相关用法: 变量作为被赋值的一方的时候不加$,只有在使用其值的内容的时候需要加上$,该符号可 1,变量中的单引号‘’.双引号“”“.反单引号‵`.括号().大括号{}.双括号(() ...

  3. Initialization of bean failed; nested exception is java.lang.

    网上搜寻各种解说,applicationContext-hibernate.xml 配置错误,jar冲突等等 现场错误图: 解决方法: asm-attrs.jar cglib-nodep-2.1_3. ...

  4. jmeter的日常特殊参数化

    1.map转译符号:   如果///Mobile///:///18888888888///   需要再参数化请这样做,////Mobile////://///${Mobile}/////   2.in ...

  5. 内存地址 Memory Management

    Memory Management https://docs.python.org/2/c-api/memory.html Memory management in Python involves a ...

  6. 主流架构 : MVP

    1 背景 MVC 平时开发APP时会发现,activity职责非常重.以MVC角度来看: M:model数据操作层(网络请求,耗时操作,数据存取,其他逻辑操作) V:view,指xml布局文件,其实并 ...

  7. 简单三步同步你的 VSCode 用户配置

    https://www.cnblogs.com/knight-errant/p/10444777.html 设备重装,换设备,VSCode 又要重新配置了?不不不,简单三步,让你的 VSCode 配置 ...

  8. jmeter逻辑控制详解(1)

    逻辑控制器 Jmeter提供了多种逻辑控制器,下面进行讲解说明: 1.Simple Controller 简单控制器是最基本的控制器,对jmeter测试运行没有任何影响,可以将某些请求归集在一个简单控 ...

  9. tbox新增stackless协程支持

    tbox之前提供的stackfull协程库,虽然切换效率已经非常高了,但是由于每个协程都需要维护一个独立的堆栈, 内存空间利用率不是很高,在并发量非常大的时候,内存使用量会相当大. 之前考虑过采用st ...

  10. HTTP response status

    The status code is a 3-digit number: 1xx (Informational): Request received, server is continuing the ...