启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
重启一个服务:systemctl restart firewalld.service
显示一个服务的状态:systemctl status firewalld.service
在开机时启用一个服务:systemctl enable firewalld.service
在开机时禁用一个服务:systemctl disable firewalld.service
查看服务是否开机启动:systemctl is-enabled firewalld.service
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed
3.配置firewalld-cmd
1、运行命令:
firewall-cmd --get-active-zones
运行完成之后,可以看到zone名称,如下:
2、执行如下命令命令:
firewall-cmd --zone=public --add-port=6379/tcp --permanent
3、重启防火墙,运行命令:
firewall-cmd --reload
4、查看端口号是否开启,运行命令:
firewall-cmd --query-port=6379/tcp
--------------------- https://blog.csdn.net/zx110503/article/details/78787483 ----来源2
补充(限制IP段或允许IP段):
来源:https://blog.csdn.net/ywd1992/article/details/80401630
一、查看防火墙状态
1、首先查看防火墙是否开启,如未开启,需要先开启防火墙并作开机自启
systemctl status firewalld
开启防火墙并设置开机自启
systemctl start firewalld
systemctl enable firewalld
一般需要重启一下机器,不然后面做的设置可能不会生效
二、开放或限制端口
1、开放端口
(1)如我们需要开启XShell连接时需要使用的22端口
firewall-cmd --zone=public --add-port=22/tcp --permanent
其中--permanent的作用是使设置永久生效,不加的话机器重启之后失效
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd --reload
(3)可通过如下命令查看是否生效
firewall-cmd --zone=public --query-port=22/tcp
(4)如下命令可查看当前系统打开的所有端口
firewall-cmd --zone=public --list-ports
2、限制端口
(1)比如我们现在需要关掉刚刚打开的22端口
firewall-cmd --zone=public --remove-port=22/tcp --permanent
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd --reload
(3)再去查看系统所有开放的端口,已经看到没有22端口了
firewall-cmd --zone=public --list-ports
3、批量开放或限制端口
(1)批量开放端口,如从100到500这之间的端口我们全部要打开
firewall-cmd --zone=public --add-port=100-500/tcp --permanent
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd --reload
(3)查看系统所有开放的端口,可以看到从100到500的端口已被全部开放
firewall-cmd --zone=public --list-ports
(4)同理,批量限制端口为
firewall-cmd --zone=public --remove-port=100-500/tcp --permanent
firewall-cmd --reload
三、开放或限制IP
1、限制IP地址访问
(1)比如限制IP为192.168.0.200的地址禁止访问80端口即禁止访问机器
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.200" port protocol="tcp" port="80" reject"
rule
rule可以用来定义一条复杂的规则,其在zone配置文件中的节点定义如下
< zone > < rule [ family = "ipv4|ipv6" ]> [ < source address = "address[/mask]" [ invert = "bool" ]/> ] [ < destination address = "address[/mask]" [ invert = "bool" ]/> ] [ < service name = "string" /> | < port port = "portid[-portid]" protocol = "tcp|udp" /> | < protocol value = "protocol" /> | < icmp-block name = "icmptype" /> | < masquerade /> | < forward-port port = "portid[-portid]" protocol = "tcp|udp" [ to-port = "portid[-portid]" ] [ to-addr = "address" ]/> ] [ < log [ prefix = "prefixtext" ] [ level = "emerg|alert|crit|err|warn|notice|info|debug" ]/> [< limit value = "rate/duration" />] </ log > ] [ < audit > [< limit value = "rate/duration" />] </ audit > ] [ < accept /> | < reject [ type = "rejecttype" ]/> | < drop /> ] </ rule > </ zone > |
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd --reload
(3)查看已经设置的规则
firewall-cmd --zone=public --list-rich-rules
2、解除IP地址限制
(1)解除刚才被限制的192.168.0.200
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.0.200" port protocol="tcp" port="80" accept"
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd --reload
(3)再查看规则设置发现已经没有192.168.0.200的限制了
firewall-cmd --zone=public --list-rich-rules
如设置未生效,可尝试直接编辑规则文件,删掉原来的设置规则,重新载入一下防火墙即可
vi /etc/firewalld/zones/public.xml
3、限制IP地址段
(1)如我们需要限制10.0.0.0-10.0.0.255这一整个段的IP,禁止他们访问
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.0.0.0/24" port protocol="tcp" port="80" reject"
其中10.0.0.0/24表示为从10.0.0.0这个IP开始,24代表子网掩码为255.255.255.0,共包含256个地址,即从0-255共256个IP,即正好限制了这一整段的IP地址,具体的设置规则可参考下表
(2)重新载入一下防火墙设置,使设置生效
firewall-cmd --reload
(3)查看规则,确认是否生效
firewall-cmd --zone=public --list-rich-rules
(4)同理,打开限制为
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="10.0.0.0/24" port protocol="tcp" port="80" accept"
firewall-cmd --reload
---------------------
作者:咖啡那么浓
来源:CSDN
原文:https://blog.csdn.net/ywd1992/article/details/80401630
版权声明:本文为博主原创文章,转载请附上博文链接!