Tuesday, September 17, 2019

reverse proxy - Transparently forward SSH connections to NATed Servers



I've been trying this for a long time and I have not yet found a good solution. I have several servers behind a NAT that all run an SSH daemon. One of the machines is my main server which gets the SSH port forwarded to it. What I want is basically open a connection to other NATed servers by going through the main server similar to what I can achieve by opening a connection to the main server and then SSHing in to the destination. Since there are some applications that run on top of SSH I'd like to make automate this in order to run rsync or git on top of the connection itself.



Is there a reverse proxy for SSH?


Answer



You can do this using ProxyCommand and netcat in .ssh/config:




# Your 'gateway' server.
Host gateway

# Any other server.
Host server1
ProxyCommand ssh gateway /bin/netcat %h %p


If you do ssh server1, you will open an SSH connection from your current location to your 'gateway' server, which will open a TCP connection to server1. This TCP connection will serve as the connection for SSH between your current location and server1.




Edit: This technique is commonly called 'ssh jumphost'.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...