防火墙相关

这里是以CentOS 7为例

系统配置目录

1
2
3
/usr/lib/firewalld/
/usr/lib/firewalld/services
/usr/lib/firewalld/zones

用户配置目录

1
2
3
/etc/firewalld/
/etc/firewalld/services
/etc/firewalld/zones

firewall常用命令

1
2
3
4
5
6
7
8
9
10
11
12
# 启动 停止 重启 状态
systemctl start firewalld / service firewalld start
systemctl stop firewalld / service firewalld stop
systemctl restart firewalld / service firewalld restart
systemctl status firewalld / service firewalld status / firewall-cmd --state

# 开启/关闭开机自启动
systemctl enable firewalld
systemctl disable firewalld

# 查看防火墙规则
firewall-cmd --list-all

修改配置文件来开放外部访问3306端口

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="dhcpv6-client"/>
<service name="ssh"/>
<port protocol="tcp" port="3306"/> # 添加这一行
</zone>

也可以通过命令行来实现

1
2
3
4
5
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=8082/tcp --permanent
firewall-cmd --zone=public --add-port=8000/tcp --permanent
firewall-cmd --reload