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 分钟前
WSL2 从 img 镜像文件启动特定 Linux 发行版完整指南
linux·windows·wsl
tachibana21 小时前
hot100 回文链表(234)
java·网络·数据结构·leetcode·链表
瓶中怪1 小时前
ROS2 机器人软件系统
linux·c++·python·ubuntu·vmware·ros2·机器人软件开发
iangyu1 小时前
linux配置时间同步
linux·运维·服务器
天空'之城2 小时前
Linux 系统编程 04:进程基础
linux·开发语言·进程基础
从零开始的代码生活_2 小时前
NAT、代理服务与内网穿透详解
linux·服务器·网络·c++·http·智能路由器
云栖梦泽在2 小时前
Claude Code / Codex 使用卡顿怎么办?AI 编程 Agent 连接失败与网络排查思路
网络·人工智能·网络协议·chatgpt·性能优化
灯厂码农2 小时前
C语言内存管理——内存对齐与共用体union
linux·服务器·c语言
Jeremy_WW2 小时前
QSFP-DD MSA Hardware协议解读(二)
网络·模块测试·智能硬件
深盾科技_Virbox2 小时前
加密狗授权能力选型:从授权模型到全生命周期管理
java·网络·数据库