CentOS 7 的防火墙开启 http 80 端口
封面图
•
2025-10-18
•
Linux
155
0
0
0
在 CentOS 7 中,默认使用的是 **firewalld** 防火墙服务,而不是旧的 `iptables`。以下是开启 HTTP(80)端口的步骤: --- ### ✅ 步骤 1:检查 firewalld 是否正在运行 ```bash systemctl status firewalld ``` 如果未运行,可以启动并设置开机自启: ```bash systemctl start firewalld systemctl enable firewalld ``` --- ### ✅ 步骤 2:添加 HTTP 端口(80)到防火墙规则中 ```bash firewall-cmd --permanent --add-port=80/tcp ``` > - `--permanent` 表示永久生效,重启后不会丢失。 > - `--add-port=80/tcp` 表示允许 TCP 协议的 80 端口。 --- ### ✅ 步骤 3:重新加载防火墙配置 ```bash firewall-cmd --reload ``` --- ### ✅ 步骤 4:验证是否成功添加了 80 端口 ```bash firewall-cmd --list-all ``` 你应该会看到类似如下内容: ``` public (default, active) interfaces: sources: services: dhcpv6-client ssh ports: 80/tcp masquerade: no forward-ports: icmp-blocks: rich rules: ``` --- ### 📌 可选:开放 HTTP 服务(firewalld 服务方式) 你也可以直接开放 `http` 服务(它默认使用 80 端口): ```bash firewall-cmd --permanent --add-service=http firewall-cmd --reload ``` --- ### ✅ 总结命令汇总: ```bash # 启动 firewalld systemctl start firewalld systemctl enable firewalld # 开放 80 端口 firewall-cmd --permanent --add-port=80/tcp firewall-cmd --reload # 或者开放 http 服务 firewall-cmd --permanent --add-service=http firewall-cmd --reload ``` --- 如果你使用的是 `iptables` 而不是 `firewalld`(虽然不推荐),请告诉我,我可以提供相应的配置方法。
上一篇:
centOS系统时间查看与设置
下一篇:
CentOS 7设置开机启动服务
标题录入,一次不能超过6条
返回顶部
留言
留言
评论