Linux CentOS7 设置防火墙使apache及mysql可以被外部访问

1、关闭firewall

# systemctl stop firewalld.service

2、禁止firewall开机启动

# systemctl disable firewalld.service

3、安装iptables防火墙

# yum install -y iptables-services

4、编辑防火墙配置文件

# vi /etc/sysconfig/iptables

5、按i进入insert模式,看下图,将下面的插入,80端口端口是给apache开放的,3306是给mysql的。

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 >-j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport >3306 -j ACCEPT
在这里插入图片描述

然后按ESC退出INSERT模式,输入:wq保存并回车退出

6、重启防火墙使配置生效

# systemctl restart iptables.service

7、设置防火墙开机启动

# systemctl enable iptables.service

8、关闭SELINUX,修改配置文件。

# vi /etc/selinux/config

9、按i进入INSERT模式,

将SELINUXTYPE=targeted #注释掉

按ESC退出,输入:wq保存并退出

10、使配置立即生效

# setenforce 0

猜你喜欢

转载自blog.csdn.net/weikaixxxxxx/article/details/83445164