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
相关推荐
likfishdn6 分钟前
Linux的文件与目录管理
linux·运维·服务器
2501_9032386517 分钟前
Git Bash:Windows下的强大命令行工具
windows·git·bash·个人开发
chian-ocean26 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=27 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
一只小姜丝3321 小时前
解决各大浏览器中http地址无权限调用麦克风摄像头问题
网络·vue.js·网络协议·http
吃汤圆的抹香鲸1 小时前
GoLand 安装包 绿色版 Win,Mac,Linux 包含IntelliJ全家桶 专为Go语言设计的集成开发环境(IDE)
linux·windows·macos·go·intellij-idea·go1.19
追寻光1 小时前
Cannot find a valid baseurl for repo: base/7/x86_64
linux
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
陆沙1 小时前
deepseek-r1-centos-本地服务器配置方法
linux·服务器·centos
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net