Linux防火墙Firewall-cmd 基础

一、简介

​ firewall-cmd 是firewalld服务的一个命令行客户端,提供了对防火墙规则的增删查改。firewalld自身并不具备防火墙的功能。它和iptables一样需要通过内核netfilter来实现防火墙的功能,相对于iptables来说firewall-cmd使用起来更简单。

二、防火墙的启动停止(centos7以上)

 systemctl  status  firewalld.service  #查看防火墙状态
 
 systemctl start firewalld.service     #启动防火墙
 
 systemctl stop firewalld.service      #停止防火墙
 
 systemctl restart firewalld.service   #重新启动防火墙
 
 systemctl enable firewalld.service    #设置防火墙开机自启动
 
 systemctl disable firewalld.service   #禁止防火墙开机自启动
 
  

二、firewall-cmd参数介绍

1.常规参数
 -h,--help     #显示帮助文档
 
--version      #显示版本信息

-q,--quiet     #不打印状态信息
2. 状态参数
--state                #检查firewalld服务运行状态

--reload               #不中断服务重新加载防火墙规则

--complete-reload      #中断所有连接重新加载防火墙规则

--runtime-to-permanent #将当前防火墙的规则永久保存

--check-config         # 检查配置正确性

--get-log-denied       #获取被拒绝的日志,日志没打开则为off

 #设置记录被拒绝的日志,只能为‘all’,‘unicast’,‘broadcast’,‘multicast’,‘off’ 其中的一个;
-–set-log-denied=off   

三、firewall-cmd 使用实例

​ firewall-cmd 命令的参数实在是太多了,下面只列出了一些常用到的功能,后面如果用到了新的再来补充吧!
更详细的介绍可以看官方文档:https://firewalld.org/documentation/man-pages/firewall-cmd

1、 查看开放的端口
firewall-cmd  --list-ports 
2、开放端口
#将端口添加到域 public,重启防火墙后失效
firewall-cmd  --zone=public  --add-port=3456/tcp  # tcp 可以是 {'tcp'|'udp'|'sctp'|'dccp'}中的一个

#将端口添加到域 public,想要永久生效,添加 --permanent 参数
 firewall-cmd  --zone=public  --add-port=3456/tcp --permanent 
3、关闭开放的端口
 #将端口从域 public 中删除,重启防火墙后失效
 firewall-cmd  --zone=public  --remove-port=3456/tcp
 
 #将端口从域 public 中删除,想要永久生效,添加 --permanent 参数 
 firewall-cmd  --zone=public  --remove-port=3456/tcp --permanent 
4、设置域
# 设置默认接口区域,立即生效无需重启
firewall-cmd --set-default-zone=public
posted @ 2019-11-17 22:42  ay-a  阅读(866)  评论(0编辑  收藏  举报