22.firewalld
1.firewalld 中常用的区域名称及策略规则

2.firewalld-cmd 命令中使用的参数以及作用

与 Linux 系统中其他的防火墙策略配置工具一样,使用firewalld 配置的防火墙策略默认为运行时(Runtime)模式,又称为当前生效模式,而且随着系统的重启会失效。
如果想让配置策略一直存在,就需要使用永久(Permanent)模式了,方法就是在用firewall-cmd 命令正常设置防火墙策略时添加--permanent 参数,这样配置的防火墙策略就可以永久生效了。
但是,永久生效模式有一个“不近人情”的特点,就是使用它设置的策略只有在系统重启之后才能自动生效。如果想让配置的策略立即生效,需要手动执行firewall-cmd --reload 命令。
查看 firewalld 服务当前所使用的区域:
[root@centos ~]# firewall-cmd --get-default-zone
public
查询ens33 网卡在firewalld 服务中的区域
[root@centos ~]# firewall-cmd --get-zone-of-interface=ens33
public
把 firewalld 服务中ens33 网卡的默认区域修改为external,并在系统重启后生效。分别查看当前与永久模式下的区域名称:
[root@centos ~]# firewall-cmd --permanent --zone=external --change-interface=ens33
success
[root@centos ~]# firewall-cmd --get-zone-of-interface=ens33
external
[root@centos ~]# firewall-cmd --permanent --get-zone-of-interface=ens33
no zone
把 firewalld 服务的当前默认区域设置为public:
root@centos ~]# firewall-cmd --set-default-zone=public
success
[root@centos ~]# firewall-cmd --get-default-zone
public
启动/关闭firewalld 防火墙服务的应急状况模式,阻断一切网络连接(当远程控制服务器时请慎用):
[root@centos ~]# firewall-cmd --panic-on
success
[root@centos ~]# firewall-cmd --panic-off
success
查询 public 区域是否允许请求SSH 和HTTPS 协议的流量:
[root@centos ~]# firewall-cmd --zone=public --query-service=ssh
yes
[root@centos ~]# firewall-cmd --zone=public --query-service=https
no
把 firewalld 服务中请求HTTPS 协议的流量设置为永久允许,并立即生效:
[root@centos ~]# firewall-cmd --zone=public --add-service=https
success
[root@centos ~]# firewall-cmd --permanent --zone=public --add-service=https
success
[root@centos ~]# firewall-cmd --reload
success
把 firewalld 服务中请求HTTP 协议的流量设置为永久拒绝,并立即生效:
[root@centos ~]# firewall-cmd --permanent --zone=public --remove-service=http
Warning: NOT_ENABLED: http
success
[root@centos ~]# firewall-cmd --reload
success
把在firewalld 服务中访问8080 和8081 端口的流量策略设置为允许,但仅限当前生效:
[root@centos ~]# firewall-cmd --zone=public --add-port=8080-8081/tcp
success
[root@centos ~]# firewall-cmd --zone=public --list-ports
8080-8081/tcp
把原本访问本机 888 端口的流量转发到22 端口,要且求当前和长期均有效:
流量转发命令格式为 firewall-cmd --permanent --zone=<区域> --add-forward-port=port=<源端口号>:proto=<协议>:toport=<目标端口号>:toaddr=<目标IP 地址>
[root@centos ~]# firewall-cmd --permanent --zone=public --add-forward-port=port=888:proto=tcp:toport=22:toaddr=192.168.10.10
success
[root@centos ~]# firewall-cmd --reload
success
firewalld 中的富规则表示更细致、更详细的防火墙策略配置,它可以针对系统服务、端口号、源地址和目标地址等诸多信息进行更有正对性的策略配置。它的优先级在所有的防火墙策略中也是最高的。
比如,我们可以在firewalld 服务中配置一条富规则,使其拒绝192.168.10.0/24 网段的所有用户访问本机的ssh 服务(22 端口):
[root@centos ~]# firewall-cmd --permanent --zone=public --add-rich-rule="
rule family="ipv4" source address="192.168.10.0/24" service name="ssh" reject"
success
[root@centos ~]# firewall-cmd --reload
success
在客户端使用 ssh 命令尝试访问192.168.10.10 主机的ssh 服务(22 端口):
[root@client A ~]# ssh 192.168.10.10
Connecting to 192.168.10.10:22...
Could not connect to '192.168.10.10' (port 22): Connection failed.
22.firewalld的更多相关文章
- iptables规则备份和恢复、firewalld的9个zone、以及firewalld关于zone和service的操作 使用介绍
第7周第5次课(5月11日) 课程内容: 10.19 iptables规则备份和恢复10.20 firewalld的9个zone10.21 firewalld关于zone的操作10.22 firewa ...
- centos 7.0 修改ssh默认连接22端口 和 添加防火墙firewalld 通过端口
首先 先做的就是 修改ssh的默认端口22 需要修改文件 /etc/ssh/sshd_config 使用命令 vi /etc/ssh/sshd_config [root@localhost ~]# v ...
- Linux网络相关命令firewalld和netfilter、iptables 使用(6/22)
iptables和netfilter的关系: netfilter在内核空间的代码根据table中的rules,完成对packet的分析和处置.但是这些table中的具体的防火墙rules,还是必须由系 ...
- Linux防火墙配置(iptables, firewalld)
netfilter和底层实现 iptables firealld Linux中的防火墙 RHEL中有几种防火墙共存: iptables firewalld ip6tables ebtables 这些软 ...
- centos7 开启防火墙端口 firewalld
systemctl start firewalld firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd -- ...
- 第8章 Iptables与Firewalld防火墙
章节简述: 红帽RHEL7系统已经用firewalld服务替代了iptables服务,新的防火墙管理命令firewall-cmd与图形化工具firewall-config. 本章节基于数十个防火墙需求 ...
- centos7通过firewalld更改sshd端口
1.设置selinux端口 [root@hn ~]# semanage port -l|grep ssh -bash: semanage: 未找到命令 [root@hn ~]# whereis sem ...
- CentOS7安全设置 yum-cron系统自动更新,firewalld防火墙简单使用
PermitRootLogin nosystemctl restart sshd.service; yum -y install firewalld; systemctl start firewall ...
- FirewallD 详解
在CentOS7开始,默认是没有iptables的,而是使用了firewall防火墙.与时俱进,简单的整理了一下firewall的使用方法.关于详细的介绍参考官网,就不搬字了.这个网站有中文选项.可以 ...
随机推荐
- C语言中一维数组
(1)输出数组元素 #include<stdio.h> int main() { int index; /*定义循环变量*/ int iArray[6]={0,1,2,3,4,5}; /* ...
- 源码编译搭建LNMP环境
LNMP源码编译 1.LNMP介绍 LNMP=Linux Nginx Mysql PHP Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器.Ng ...
- 使用BigDecimal舍小数取整数
项目需求说明: 解决WMS系统收货容差问题,例如:SKU的采购数量95件,容差是5,95+95*5/100=99.75,传WMS的数量是99,且容差传零. 参数说明: 其中ROUND_UP:向上取整, ...
- 项目实战--JSON.toJSONString()
需求说明:公司使用Swagger(接口文档在线生成工具),为了让前端同事更好的了解传入参数的详细情况,应用项目中接口(eg:分页查询接口)中使用dto对象来接受前端传入的参数,但是后面中心项目中接口是 ...
- Sentry(v20.12.1) K8S 云原生架构探索,SENTRY FOR JAVASCRIPT SDK 配置详解
系列 Sentry-Go SDK 中文实践指南 一起来刷 Sentry For Go 官方文档之 Enriching Events Snuba:Sentry 新的搜索基础设施(基于 ClickHous ...
- OpenTelemetry - 云原生下可观测性的新标准
CNCF 简介 CNCF(Cloud Native Computing Foundation),中文为"云原生计算基金会",CNCF是Linux基金会旗下的基金会,可以理解为一个非 ...
- VMware 安装 Centos7 超详细过程
https://www.runoob.com/w3cnote/vmware-install-centos7.html centos7安装参考文档 VMware 安装 Centos7 超详细过程 分类 ...
- Spring Boot 计划任务中的一个“坑”
计划任务功能在应用程序及其常见,使用Spring Boot的@Scheduled 注解可以很方便的定义一个计划任务.然而在实际开发过程当中还应该注意它的计划任务默认是放在容量为1个线程的线程池中执行, ...
- 【Flutter】容器类组件之剪裁
前言 Flutter中提供了一些剪裁函数,用于对组件进行剪裁. 剪裁Widget 作用 ClipOval 子组件为正方形时剪裁为内贴圆形,为矩形时,剪裁为内贴椭圆 ClipRRect 将子组件剪裁为圆 ...
- SpringCloud Gateway快速入门
SpringCloud Gateway cloud笔记第一部分 cloud笔记第二部分Hystrix 文章目录 SpringCloud Gateway Zull的工作模式与Gateway的对比 Rou ...