Linux使用——Linux命令——CentOS7防火墙使用

时间:2023-03-08 22:08:41

注意:设置防火墙需要使用具有root权限的用户进入;

   CentOS 7.0默认使用的是firewall作为防火墙;

   CentOS 7.0使用systemctl来管理服务和程序,包括了service和chkconfig。所以在开启或者关闭进程时,需要使用systemctl命令。


  • 开启防火墙:systemctl start firewalld

  • 关闭防火墙:systemctl stop firewalld

  • 重启防火墙:systemctl restart firewalld

  • 开机时启动防火墙:systemctl enable firewalld

  • 开机时禁用防火墙:systemctl disable firewalld

  • 查看已经启动服务列表:systemctl list-unit-files|grep enabled

  • 检查防火墙状态
    • systemctl status firewalld
    • firewall-cmd --state

  • 添加端口:firewall-cmd --zone=public --add-port=8080/tcp --permanent
    • --zone    作用域
    • --add-port=8080/tcp    添加端口,格式为:端口/通讯协议
    • --permanent       永久生效,没有此参数重启服务器或者防火墙后失效

  • 添加服务:firewall-cmd --zone=public --add-service=service --permanent