在 CentOS 中,“导入防火墙规则”通常有 两种常见场景,取决于你使用的是哪种防火墙:
如果你之前导出过 firewalld 配置(如 public.xml):
cp public.xml /etc/firewalld/zones/
systemctl restart firewalld
或重新加载:
firewall-cmd --reload
如果你有一批命令,可以写成脚本:
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" accept'
firewall-cmd --reload
firewalld 不直接支持 iptables 规则文件导入,需要手动转换。
如果你有导出文件(如 iptables.rules):
iptables-restore < iptables.rules
查看当前规则:
iptables -L -n
service iptables save
chkconfig iptables on
CentOS 7+(若使用 iptables 服务):
systemctl enable iptables
systemctl start iptables
导出:
iptables-save > rules.txt
导入:
iptables-restore < rules.txt
| 系统 | 推荐方式 |
|---|---|
| CentOS 7/8 | firewalld |
| 老系统 / 特殊需求 | iptables |
如果你能告诉我:
我可以给你 精确的一步一步操作。