Linux防火的常用命令

文章目录

防火墙查看状态

  • 防火墙重新载入(必须重新载入后才能生效)
shell 复制代码
firewall-cmd --reload
  • 防火墙查看基础状态
shell 复制代码
systemctl status firewalld #查看状态
  • 查看 防火墙所有规则
shell 复制代码
firewall-cmd --list-all
  • 查看rich-rules(富规则)
shell 复制代码
firewall-cmd --list-rich-rules
  • 查看防火墙服务规则
shell 复制代码
firewall-cmd --list-services
  • 查看防火墙所有区域的配置规则
shell 复制代码
firewall-cmd --list-all-zones
  • 查看默认区域
shell 复制代码
firewall-cmd --get-default-zone
  • 查看网络接口使用区域
shell 复制代码
firewall-cmd --get-active-zones
  • 查看默认的可用服务
shell 复制代码
firewall-cmd --get-services

防火墙启动关闭命令

  • 启动
shell 复制代码
systemctl start firewalld #启动
  • 停止
shell 复制代码
systemctl stop firewalld #停止
  • 重启
shell 复制代码
firewall-cmd --reload #重启
  • 开机禁用
shell 复制代码
systemctl disable firewalld #开机禁用
  • 开机启动
shell 复制代码
systemctl enable firewalld #开机启动

防火墙配置

添加规则

  • 在public中永久开放10022端口
shell 复制代码
firewall-cmd --zone=public --add-port=10022/tcp --permanent
txt 复制代码
--zone :网络区域
--permanent:永久生效,没有此参数重启后失效
  • 设置开放80端口开放
shell 复制代码
firewall-cmd --add-service=http --permanent #添加一个服务permanent
shell 复制代码
firewall-cmd --add-port=80/tcp --permanent	# permanent上开放一个80端口
  • 允许192.168.1.10所有访问所有端口
shell 复制代码
firewall-cmd --zone=public --add-rich-rule 'rule family="ipv4" source address="192.168.1.10" accept' --permanent
  • 允许192.168.2.0/24(0-255网段)所有访问所有端口
shell 复制代码
firewall-cmd --zone=public --add-rich-rule 'rule family="ipv4" source address="192.168.2.0/24" accept' --permanent

允许192.168.1.10所有访问TCP协议的22端口

shell 复制代码
firewall-cmd --zone=public --add-rich-rule 'rule family="ipv4" source address="192.168.1.10" port port=22 protocol=tcp accept' --permanent

移除规则

  • 移除permanent服务
shell 复制代码
firewall-cmd --remove-service=http --permanent 
  • 移除permanent服务上开放的80端口
shell 复制代码
firewall-cmd --remove-port=80/tcp --permanent
  • 移除192.168.1.10所有访问所有端口
shell 复制代码
firewall-cmd --zone=public --remove-rich-rule 'rule family="ipv4" source address="192.168.1.10" accept' --permanent
相关推荐
雷工笔记5 分钟前
MES 系统设备管理模块详细设计方案
大数据·运维·网络
ErizJ5 分钟前
Linux|学习笔记
linux·笔记·学习
wangchunting6 分钟前
VMware17 使用Rocky Linux 9.7系统
linux·运维·服务器
相醉为友8 分钟前
040 Linux/裸机/RTOS 项目开发的跨平台兼容性——C语言静态接口抽象底层原理分析
linux·c语言·mcu
草履虫君9 分钟前
windows系统装机,小白win10装机教程wepe模式,包括系统盘怎么制作,bios怎么设置
windows·经验分享
minxihou15 分钟前
迅雷下载导致 Windows 11 频繁卡死?一根 SATA 线的锅
windows·磁盘
xhbh66635 分钟前
端口转发是什么?如何设置端口转发?
网络·流量转发·端口流量转发
Mapleay38 分钟前
ALSA 专业术语 和 dai_link 分析
linux
S1998_1997111609•X1 小时前
论恶意注入污染蜜罐进程函数值取仺⺋以集团犯罪获取数据爬虫的轮系依据
网络·数据库·爬虫·网络协议·百度
青梅橘子皮1 小时前
Linux---权限
linux·运维·服务器