Linux 防火墙开启端口



在这里插入图片描述

以下是一些常用的 firewalld 命令:


本文仅适用于CentOS7

查看防火墙状态

firewall-cmd --state

在这里插入图片描述

  • 返回结果
  • running : 开启了
  • not running :未开启

为了保证安全起见,如果未开启防火墙,请先开启防火墙,命令如下:

systemctl start firewalld.service

开启指定端口

例如:开启 8848 端口

firewall-cmd --zone=public --add-port=8848/tcp --permanent

显示 success 表示成功


重启防火墙

systemctl restart firewalld.service

系统没有任何提示表示成功!


重新加载防火墙

firewall-cmd --reload

在这里插入图片描述

显示 success 表示成功


查看已开启的端口

firewall-cmd --list-ports

在这里插入图片描述

关闭指定端口

firewall-cmd --zone=public --remove-port=8080/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --reload

临时关闭防火墙

systemctl stop firewalld.service
# 或者
systemctl stop firewalld

永久关闭防火墙(必须先临时关闭防火墙,再执行该命令,进行永久关闭)

systemctl disable firewalld.service
# 或者
systemctl disable firewalld

请慎重永久关闭防火墙 !!!



结语


Linux 系统的防火墙主要有两种,一种是 iptables,一种是 firewalld。

iptables 是一个命令行工具,是 Linux 系统内置的防火墙程序。它通过过滤网络数据包来保护服务器安全,并降低攻击风险。iptables 可以根据不同的规则对进出服务器的流量进行控制,因此可用于限制特定 IP 地址或端口的访问等操作。iptables 虽然灵活高效,但配置起来比较复杂,需要熟悉其各项规则和操作知识。

firewalld 则相对简单易用。它是一个更高级的动态防火墙管理工具,可以通过 XML 文件配置不同的防火墙规则,支持应用程序型(application)和端口型(port)规则。firewalld 的管理工具叫做 firewall-cmd,使用起来比 iptables 更加方便。

在 CentOS 7 和 RHEL 7 及以后版本上,系统默认采用的是 firewalld。如果需要使用 iptables,则需要先卸载 firewalld,再安装 iptables,并手动配置其规则。由于 firewalld 较为普遍,以下专门介绍 CentOS 7 和 RHEL 7 上的 firewalld 防火墙相关知识。

firewalld 维护了一个固定状态和变化状态的规则集,可以转换成类似于 iptables 的格式和立即生效。


在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/m0_60915009/article/details/130968083
今日推荐