If you meet this error when trying to connect to a server via ssh, you probably think there was a network error causing this. Maybe the ip configuration is not correct on the target server. But you can indeed ping the server without problem. How does this error happen? Well, this can happen when you’ve changed the default ssh port on the target vps, and the firewalld is running with the default configuration(which is the case on my CentOS 7 initial installation). When I install a fresh CentOS 7 on my vps, the firewalld is running by default, and the default configuration of firewalld does allow the ssh service but on its default port(22). Thus, the sshd service with the changed port is blocked and the error occurs.
To solve this problem, you can add port for the default zone of firewalld, or just start iptables service to replace the firewalld. When you start iptables service, the firewalld is shutdown automatically. Of course, your iptables service must allow the new ssh port.