作者:irokay
链接:https://blog.csdn.net/irokay/article/details/72717132
复制代码
背景:在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”键即可。
PS:-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT,就是在系统防火墙中添加端口规则,插入后重启防火墙即可
复制代码
先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可能,综合处理访问权限问题。复制代码