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的使用方法.关于详细的介绍参考官网,就不搬字了.这个网站有中文选项.可以 ...
随机推荐
- 1. 内存分区模型以及new、delete操作
C++程序在执行时,将内存大方向分为 4 个区域,不同区域存放的数据,赋予不同的生命周期,给我们更大的灵活编程 代码区:存放函数二进制代码,由操作系统进行管理 全局区:存放全局变量和静态数据以及常量, ...
- 编写 Dockerfile 生成自定义镜像
一般情况下我们可以从公共渠道诸如 DockerHub 获取镜像上获取镜像,但是在实际生产过程中,往往需要定制化的镜像,例如修改一些配置文件,增加一些特殊的命令或软件等需求,这时就需要通过编写 Dock ...
- 风炫安全WEB安全学习第二十五节课 利用XSS键盘记录
风炫安全WEB安全学习第二十五节课 利用XSS键盘记录 XSS键盘记录 同源策略是浏览器的一个安全功能,不同源的客户端脚本在没有明确授权的情况下,不能读写对方资源.所以xyz.com下的js脚本采用a ...
- 如何制作sitemaps网站地图
如何制作sitemaps网站地图 1.0 前言 1.1 xml格式 1.2 常见问题 本文资料来源于网站 1.0 前言 Sitemap 可方便网站管理员通知搜索引擎他们网站上有哪些可供抓取的网页.最简 ...
- Mac M1原生(ARM64)Golang dev&debug
前言 通过本文最终实现了在M1芯片的Mac mini上的Goland的开发,并通过编译源码解决了无法DEBUG的问题. Go 1.16版将正式支持Apple Silicon M1芯片,即arm64架构 ...
- Ossec 安装并配置邮件通知
Ossec 安装并配置邮件通知 目录 Ossec 安装并配置邮件通知 1. 介绍 2. 软硬件环境 3. 安装步骤 3.1 Server 3.2 Agent 3.3 配置邮件通知 4. 参考资料 1. ...
- Java 使用 commons-fileupload 实现文件上传工具类
依赖包 文件上传可以使用 Apache 文件上传组件, commons-fileupload, 它依赖于 commons-io commons-io.jar: https://repo1.maven. ...
- Java 在windows中配置Maven环境和阿里云镜像
目录 1. 下载Maven 2. 配置环境变量 3. 配置镜像 4. 配置本地仓库 1. 下载Maven 官网:https://maven.apache.org/ 下载:apache-maven-3. ...
- Nacos(二)源码分析Nacos服务端注册示例流程
上回我们讲解了客户端配置好nacos后,是如何进行注册到服务器的,那我们今天来讲解一下服务器端接收到注册实例请求后会做怎么样的处理. 首先还是把博主画的源码分析图例发一下,让大家对整个流程有一个大概的 ...
- 【System】I/O密集型和CPU密集型工作负载之间有什么区别
CPU密集型(CPU-bound) CPU密集型也叫计算密集型,指的是系统的硬盘.内存性能相对CPU要好很多,此时,系统运作大部分的状况是CPU Loading 100%,CPU要读/写I/O(硬盘/ ...