1.查看防火墙状态:active (running) 即是开启状态
systemctl status firewalld
2.查看已开发端口命令:
firewall-cmd --list-all
3.新增防火墙开放端口:
firewall-cmd --zone=public --add-port=3306/tcp --permanent
命令含义:
--zone #作用域
--add-port=3306/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
4.开放端口后需要重新加载防火墙:
firewall-cmd --reload
的基本使用命令:
启动: systemctl start firewalld
关闭: systemctl stop firewalld
查看状态: systemctl status firewalld
开机禁用 : systemctl disable firewalld
开机启用 : systemctl enable firewalld
6.配置firewalld-cmd命令
查看版本: firewall-cmd --version
查看帮助: firewall-cmd --help
显示状态: firewall-cmd --state
查看所有打开的端口: firewall-cmd --zone=public --list-ports
更新防火墙规则: firewall-cmd --reload
查看区域信息: firewall-cmd --get-active-zones
查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0
拒绝所有包:firewall-cmd --panic-on
取消拒绝状态: firewall-cmd --panic-off
查看是否拒绝: firewall-cmd --query-panic查询指定端口是否已开 : firewall-cmd --query-port=3306/tcp
移除指定端口:firewall-cmd --permanent --remove-port=3306/tcp
相关命令
启动一个服务:systemctl start
关闭一个服务:systemctl stop
重启一个服务:systemctl restart
显示一个服务的状态:systemctl status
在开机时启用一个服务:systemctl enable
在开机时禁用一个服务:systemctl disable
查看服务是否开机启动:systemctl is-enabled
查看已启动的服务列表:systemctl list-unit-files|grep enabled
查看启动失败的服务列表:systemctl --failed
8. 查看端口号
netstat -ntlp //查看当前所有tcp端口·
netstat -ntulp |grep 3306 //查看所有3306 端口使用情况·
9. 设置端口报错
$ firewall-cmd --zone=public --add-port=3306/tcp --permanent
Authorization failed.
Make sure polkit agent is running or run the application as superuser.
$
--切换root账户,或者使用sudo进行处理
10. 若遇到无法开启
先用:systemctl unmask
然后:systemctl start