Files
StudyDiary/10-WebClipper/OpenCloudOS 8.6 防火墙?-PHPWP博客.md
2026-07-23 20:36:13 +08:00

160 lines
5.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
2025-10-28 12:00:00 分类:[云计算](https://www.phpwp.cn/article/category/calc)
云服务器导航,点击直达:[阿里云](https://www.aliyun.com/minisite/goods?userCode=cb3vgkf5),[腾讯云](https://cloud.tencent.com/act/cps/redirect?redirect=2853&cps_key=bb14eb9f876cbac6a078a1fb7f9c896d&from=console),[京东云](https://3.cn/1YX-MxJv),[百度云](https://cloud.baidu.com/campaign/ambassador-product/index.html?ambassadorId=2ac14a4d64c04879b419d2f576cd2e5f),[UCloud](https://www.ucloud.cn/site/active/hk-global.html?cps_code=AozWP2tZ4IKGOtb81GiXNE)。
OpenCloudOS 8.6 是基于 Linux 的开源服务器操作系统,其防火墙机制与主流的 RHEL/CentOS/Rocky Linux 等系统类似,主要使用 `firewalld` 作为默认的动态防火墙管理工具。以下是关于 OpenCloudOS 8.6 防火墙的详细介绍和常用操作:
* * *
### 🔧 1. 默认防火墙服务:`firewalld`
* **服务名称**:`firewalld`
* **配置工具**:`firewall-cmd`(命令行)、`firewall-config`(图形界面,可选)
* **区域(Zones)**:支持多种网络区域(如 public、internal、trusted 等),用于灵活控制不同网络接口的安全策略。
* * *
### ✅ 常用防火墙操作命令
#### 🔹 启动、停止、重启 firewalld
```
# 启动防火墙
sudo systemctl start firewalld
# 设置开机自启
sudo systemctl enable firewalld
# 停止防火墙
sudo systemctl stop firewalld
# 禁用开机启动
sudo systemctl disable firewalld
# 查看状态
sudo systemctl status firewalld
```
* * *
#### 🔹 查看当前防火墙状态和规则
```
# 查看运行状态
sudo firewall-cmd --state
# 查看当前活动区域
sudo firewall-cmd --get-active-zones
# 查看默认区域
sudo firewall-cmd --get-default-zone
# 列出当前区域的规则(临时+永久)
sudo firewall-cmd --list-all
```
* * *
#### 🔹 开放端口或服务
```
# 临时开放端口(重启后失效)
sudo firewall-cmd --add-port=80/tcp
# 永久开放端口(推荐)
sudo firewall-cmd --add-port=80/tcp --permanent
# 开放某个服务(如 http、https)
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
# 重新加载配置使永久规则生效
sudo firewall-cmd --reload
```
> ⚠️ 注意:添加 `--permanent` 参数后必须执行 `--reload` 才能生效。
* * *
#### 🔹 删除规则
```
# 删除已开放的端口
sudo firewall-cmd --remove-port=80/tcp --permanent
# 删除服务
sudo firewall-cmd --remove-service=http --permanent
# 重新加载
sudo firewall-cmd --reload
```
* * *
#### 🔹 更改默认区域
```
# 设置默认区域为 public
sudo firewall-cmd --set-default-zone=public
# 将某个网卡绑定到指定区域
sudo firewall-cmd --zone=dmz --change-interface=eth0 --permanent
```
* * *
### 🛑 替代方案:`iptables`(传统方式)
虽然 `firewalld` 是默认工具,但你也可以切换回传统的 `iptables`:
```
# 停止并禁用 firewalld
sudo systemctl stop firewalld
sudo systemctl disable firewalld
# 安装 iptables-services
sudo dnf install iptables-services -y
# 启动并启用 iptables
sudo systemctl start iptables
sudo systemctl enable iptables
```
然后使用 `iptables` 命令进行规则配置。
* * *
### 🔐 安全建议
1. **生产环境不要关闭防火墙**,应通过规则精细控制访问。
2. 开放端口时尽量限制 IP 范围(使用 rich rules):```
sudo firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='192.168.1.100' port protocol='tcp' port='22' accept"
```
3. 定期检查开放的端口和服务:```
sudo firewall-cmd --list-all
ss -tuln | grep LISTEN
```
* * *
### 📚 参考文档
* OpenCloudOS 官方文档:https://opencloudos.org
* firewalld 官方手册:`man firewalld`, `man firewall-cmd`
* * *
如果你有具体需求(例如开放 Nginx/MySQL 端口、配置 NAT、多区域管理等),可以告诉我,我可以提供详细配置示例。
| 服务器 | CPU | 内存 | 磁盘 | 价格 | 购买地址 |
| 阿里云 | 2核 | 2GB | 40GB | 99元/年 | [点击查看››](https://www.aliyun.com/minisite/goods?userCode=cb3vgkf5) |
| 阿里云 | 2核 | 4GB | 80GB | 199元/年 | [点击查看››](https://www.aliyun.com/minisite/goods?userCode=cb3vgkf5) |
| 腾讯云 | 2核 | 2GB | 50GB | 118元/年 | [点击查看››](https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=bb14eb9f876cbac6a078a1fb7f9c896d) |
| 腾讯云 | 2核 | 4GB | 60GB | 252元/年 | [点击查看››](https://cloud.tencent.com/act/cps/redirect?redirect=2446&cps_key=bb14eb9f876cbac6a078a1fb7f9c896d) |
| 京东云 | 2核 | 2GB | 40GB | 50元/年 | [点击查看››](https://3.cn/1YX-MxJv) |
| 百度云 | 2核 | 2GB | 40GB | 59元/年 | [点击查看››](https://cloud.baidu.com/campaign/ambassador-product/index.html?ambassadorId=2ac14a4d64c04879b419d2f576cd2e5f) |
| 百度云 | 2核 | 8GB | 40GB | 432元/年 | [点击查看››](https://cloud.baidu.com/campaign/ambassador-product/index.html?ambassadorId=2ac14a4d64c04879b419d2f576cd2e5f) |
以实际价格为准