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
相关推荐
paopao_wu16 分钟前
DeepSeek-OCR实战(01):基础运行环境搭建-Ubuntu
linux·人工智能·ubuntu·ai·ocr
betazhou20 分钟前
基于Linux环境使用ogg19版本从oracle 19c ADG备库远程同步数据
linux·运维·oracle·goldengate·adg·远程抽取
路由侠内网穿透.24 分钟前
本地部署消息代理软件 RabbitMQ 并实现外部访问( Windows 版本 )
linux·运维·服务器·远程工作
Fanmeang1 小时前
华为防火墙基础功能详解:构建网络安全的基石
运维·网络·安全·华为·防火墙·策略·安全域
孙同学_1 小时前
【Linux篇】System V IPC详解:共享内存、消息队列与信号量
linux·服务器
铭哥的编程日记1 小时前
【Linux网络】传输层协议TCP
linux·网络·tcp/ip
MarkHD1 小时前
蓝牙钥匙 第69次 蓝牙钥匙安全与便捷性平衡:从理论到实践的全方位解析
网络·人工智能·安全
它说我会飞耶1 小时前
开机视频动画
linux
深圳佛手2 小时前
几种限流算法介绍和使用场景
网络·算法
大聪明-PLUS2 小时前
Linux 上的 GitOps:使用 Git 进行无缝基础设施管理
linux·嵌入式·arm·smarc