原因:防火墙未打开相应的端口,centos7的防火墙是firewall,网上有一些教程是用的iptables
vi /etc/ssh/sshd_config
打开ssh配置文件,注意是sshd_config,而不是ssh_congfig- 在
#Port 22
下方添加一行Port 3306
不是直接把#Port 22
注释删掉,不然后面万一出错连不上就很麻烦 systemctl status firewalld
查看状态,发现Active:dead,说明防火墙关闭systemctl start firewalld
启动防火墙systemctl status firewalld
查看状态,发现Active:runing,表明已经打开了firewall-cmd --permanent --zone=public --add-port=3306/tcp
将3306端口添加到防火墙firewall-cmd --permanent --query-port=3306/tcp
检查3306端口有没有打开,如果打开的话应该是yesfirewall-cmd --reload
重新加载防火墙策略systemctl restart sshd
重启ssh服务systemctl restart firewalld.service
重启防火墙firewall-cmd --zone=public --list-ports
查看防火墙已经开放的端口ssh root@localhost -p 3306
尝试本地连接3306,看能不能成功- 不要关闭当前的xshell窗口,新建一个会话,用3306端口,看能不能成功。
参考链接1
参考链接2
centos7服务器安装fail2ban配合Firewalld防护墙防止SSH爆破与防护网站CC攻击