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的更多相关文章

  1. 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 ...

  2. centos 7.0 修改ssh默认连接22端口 和 添加防火墙firewalld 通过端口

    首先 先做的就是 修改ssh的默认端口22 需要修改文件 /etc/ssh/sshd_config 使用命令 vi /etc/ssh/sshd_config [root@localhost ~]# v ...

  3. Linux网络相关命令firewalld和netfilter、iptables 使用(6/22)

    iptables和netfilter的关系: netfilter在内核空间的代码根据table中的rules,完成对packet的分析和处置.但是这些table中的具体的防火墙rules,还是必须由系 ...

  4. Linux防火墙配置(iptables, firewalld)

    netfilter和底层实现 iptables firealld Linux中的防火墙 RHEL中有几种防火墙共存: iptables firewalld ip6tables ebtables 这些软 ...

  5. centos7 开启防火墙端口 firewalld

    systemctl start firewalld firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd -- ...

  6. 第8章 Iptables与Firewalld防火墙

    章节简述: 红帽RHEL7系统已经用firewalld服务替代了iptables服务,新的防火墙管理命令firewall-cmd与图形化工具firewall-config. 本章节基于数十个防火墙需求 ...

  7. centos7通过firewalld更改sshd端口

    1.设置selinux端口 [root@hn ~]# semanage port -l|grep ssh -bash: semanage: 未找到命令 [root@hn ~]# whereis sem ...

  8. CentOS7安全设置 yum-cron系统自动更新,firewalld防火墙简单使用

    PermitRootLogin nosystemctl restart sshd.service; yum -y install firewalld; systemctl start firewall ...

  9. FirewallD 详解

    在CentOS7开始,默认是没有iptables的,而是使用了firewall防火墙.与时俱进,简单的整理了一下firewall的使用方法.关于详细的介绍参考官网,就不搬字了.这个网站有中文选项.可以 ...

随机推荐

  1. 第八章节 BJROBOT hector 算法构建地图【ROS全开源阿克曼转向智能网联无人驾驶车】

    1.把小车平放在地板上,用资料里的虚拟机,打开一个终端 ssh 过去主控端启动roslaunch znjrobot bringup.launch. 2.在虚拟机端打开一个终端,ssh 过去主控端启动r ...

  2. mysql词法分析和语法分析

    如果没有命中查询缓存,就要开始真正执行语句了.首先,MySQL 需要知道你要做什么,因此需要对 SQL 语句做解析.分析器先会做"词法分析".你输入的是由多个字符串和空格组成的一条 ...

  3. 一、linux安装mysql

    一.下载mysql免编译包: wget http://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.33-linux-glibc2.5-x86_64.tar.g ...

  4. linux系统重启后提示An error occurred during the file system check.

    一.问题描述 生产环境中一台浪潮NF8480M3外观红灯报警,鉴于无法登陆带外管理口,只能对服务器进行断电重启操作 二.问题现象 重启后进入开机过程并报错,正常来说进入此界面后直接输入root密码即可 ...

  5. WPF + RDLC + 动态生成列 + 表头合并

    如下,评论超过20条,马上发代码*(੭*ˊᵕˋ)੭*ଘ,效果如下: 代码逻辑简单. WPF使用RDLC需要使用如下DLL 新建WPF 窗体,黏贴下大概如下 <Window xmlns:rv=&q ...

  6. java环境配置-win10(傻瓜式教程)

    java环境配置 – 小学弟要开始学java了,由于本人较懒,表达能力有限,所以来这,写一篇简单的指导,帮学弟装下java环境. 首先打开浏览器,输入这个网址https://www.oracle.co ...

  7. 使用nodejs和express搭建http web服务

    目录 简介 使用nodejs搭建HTTP web服务 请求nodejs服务 第三方lib请求post 获取http请求的正文 Express和使用express搭建http web服务 express ...

  8. 【Problem】前端项目运行:Module build failed:Error Node Sass does not yet support my current environmen

    我在运行renren-fast-vue前端项目时,安装完依赖cnpm install 启动服务npm run dev 出现问题. Module build failed: Error: Node Sa ...

  9. LSTM+CRF进行序列标注

    为什么使用LSTM+CRF进行序列标注 直接使用LSTM进行序列标注时只考虑了输入序列的信息,即单词信息,没有考虑输出信息,即标签信息,这样无法对标签信息进行建模,所以在LSTM的基础上引入一个标签转 ...

  10. 1.5V转3.3V升压电路图和1.5V转3.3V的电源芯片

    1.5V转3.3V的电路图需要材料:PW5100芯片,2个贴片电容,1个贴片电感.即可组成一个DC-DC同步升压高效率电路图,可提供稳定的3.3V输出电压. 1.5V转3.3V的电源芯片 1.5V转3 ...