CentOS7使用iptables防火墙开放端口

背景:在CentOS上面安装了mysql、svn、tomcat等软件,发现访问不了,用telnet命令查看端口,发现都不通:

telnet IP 端口

CentOS7 默认使用firewalld防火墙,如果想换回iptables防火墙,可关闭firewalld并安装iptables。

1、关闭firewall:

停止firewall:

systemctl stop firewalld.service

禁止firewall开机启动

systemctl disable firewalld.service

查看默认防火墙状态(关闭后显示not running,开启后显示running)

firewall-cmd --state

2.安装iptables-services

yum install iptables-services

3.修改防火墙配置文件

vi /etc/sysconfig/iptables 

添加端口80、8080、3306、3690端口:

这里写图片描述

注意:添加在端口22上面或者下面,不要放在最后,不然不起作用。另外,mac上面insert输入直接按字母”i”键即可。

esc :wq! 退出保存修改。

4.重启防火墙使配置生效

systemctl restart iptables.service

设置防火墙开机启动:

systemctl enable iptables.service

再次尝试连接,成功了!

5.注意

客户端连接不了可能原因有多种,比如:

1.服务器端服务未启动

2.软件本身未开通用户访问权限
比如

a.mysql需要针对用户开放权限:

mysql授权:

grant all privileges on dbName.* to dbuser@'%' identified by 'dbpassword' with grant option;
flush privileges;

切记:一定要刷新权限。

b.svn需要事先建好仓库并配置用户、权限等信息等。

3.服务器端口被防火墙封掉。

请先排除1、2可能,综合处理访问权限问题。


https://blog.csdn.net/irokay/article/details/72717132?utm_source=copy

原文地址:https://www.cnblogs.com/lxwphp/p/9759860.html