• 场景:在新安装的CentOS7.8关闭防火墙
service iptables stop/start

报错:Failed to stop iptables.service: Unit iptables.service not loaded.

  • 原因:在CentOS7以上,防火墙的管理由friewail来管理。
    语法:
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
  • 启用端口
添加:
firewall-cmd --zone=public --add-port=80/tcp --permanent (--permanent永久生效,没有此参数重启后失效)
重新载入
firewall-cmd --reload
查看
firewall-cmd --zone=public --query-port=80/tcp
删除
firewall-cmd --zone=public --remove-port=80/tcp --permanent

传统方式管理

  • 关闭firewalld
systemctl stop firewalld
systemctl mask firewalld
  • 安装iptables-services:
yum install iptables-services
  • 设置为开机自启动
systemctl enable iptables
  • 对进行iptables进行基本操作
systemctl stop iptables
systemctl start iptables
systemctl restart iptables
systemctl reload iptables
  • iptables保存设置
service iptables save
Logo

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

更多推荐