I am using CentOs.

I can SSH from local machine to server A. I can also SSH from local machine to server B.

But I cannot SSH from server A to server B:

$ ssh -p <portB> root@B
root@B's password: 
root@B [~]# exit

$ ssh -p <portA> root@A
root@A's password: 

root@A [~]# 
root@A [~]# ssh -p <portB> root@B
ssh: connect to host B port <port>: Connection refused

Any idea why this would happen?


  • Firewall in server B only accepts connections to port B from local machine? Firewall in server B explicitly blocks port B from server A? Firewall in server A blocks outgoing access to server B or to port B (or both)? May 10, 2016 at 13:32
  • 1
    Because that is how firewalls work. Maybe Server B is configured to accept ssh from your host ip address, but not allowing ssh coming from A...
    – user34720
    May 10, 2016 at 13:38

1 Answer 1


There are a number of reasons why Server A might not be able to connect to Server B, including hardware and software firewalls, network routing, block lists, etc.

There's nothing about your two initial connections that must make the third one true (i.e. A -> B and A -> C does not imply B -> C will work).

Without more details no one will be able to say exactly what is blocking it, but the most likely thing is, as people have commented, a firewall running on or in front of server B being configured to only allow connections from certain locations.

Also, you should (if you're in control of those servers, or know who is) immediately recommend they disable access to root over ssh using passwords, it's just asking for brute-force trouble.

  • 1
    Another plausible explanation is that the network where server A is located forbids outgoing SSH connections (probably because it only allows outgoing connections that are web browsing). May 10, 2016 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .