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
相关推荐
三金121383 分钟前
SpringIoC容器的初识
网络·网络协议·rpc
韩楚风5 分钟前
【linux 多进程并发】linux进程状态与生命周期各阶段转换,进程状态查看分析,助力高性能优化
linux·服务器·性能优化·架构·gnu
陈苏同学8 分钟前
4. 将pycharm本地项目同步到(Linux)服务器上——深度学习·科研实践·从0到1
linux·服务器·ide·人工智能·python·深度学习·pycharm
Ambition_LAO14 分钟前
解决:进入 WSL(Windows Subsystem for Linux)以及将 PyCharm 2024 连接到 WSL
linux·pycharm
Pythonliu731 分钟前
茴香豆 + Qwen-7B-Chat-Int8
linux·运维·服务器
你疯了抱抱我32 分钟前
【RockyLinux 9.4】安装 NVIDIA 驱动,改变分辨率,避坑版本。(CentOS 系列也能用)
linux·运维·centos
追风赶月、32 分钟前
【Linux】进程地址空间(初步了解)
linux
栎栎学编程33 分钟前
Linux中环境变量
linux
狼头长啸李树身1 小时前
眼儿媚·秋雨绵绵窗暗暗
大数据·网络·服务发现·媒体
挥剑决浮云 -1 小时前
Linux 之 安装软件、GCC编译器、Linux 操作系统基础
linux·服务器·c语言·c++·经验分享·笔记