在 CentOS 系统中,防火墙默认使用 firewalld 管理。以下是开启指定端口的详细步骤。
步骤 1:检查防火墙状态

首先,确认防火墙是否正在运行:

systemctl status firewalld

如果未运行,可以启动防火墙:

systemctl start firewalld

步骤 2:添加开放端口

使用 firewall-cmd 命令添加需要开放的端口。例如,开放 80 和 443 端口:

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

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

–zone=public 指定作用域。

–permanent 表示永久生效(重启后仍然有效)。

步骤 3:重新加载防火墙

添加规则后,需要重新加载防火墙以使配置生效:

firewall-cmd --reload

步骤 4:验证开放端口

查看当前已开放的端口,确保配置正确:

firewall-cmd --list-ports

注意事项

如果需要临时开放端口(重启后失效),可以省略 --permanent 参数。

确保防火墙服务已设置为开机启动:

systemctl enable firewalld

通过以上步骤,您可以成功在 CentOS 系统中开启所需的防火墙端口。

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐