I have three servers in my project. Server A has a public IP address (, Server B has both public and private addresses (, and Server C only has a private IP address (

You can see that Server B and Server C are in the same private LAN.

enter image description here

Now my requirement is for Server A to connect to Server C. It would then run some commands via SSH. Is there any way to do this? Do I need any static routes or a proxy?


You can use ProxyJump/-J commandline option (if your openssh supports it):

ssh -J

or setup a DNAT on

sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -d -p tcp -m tcp --dport 2222 -j DNAT --to-destination

and connect to specific port:

ssh -p 2222

In addition to ssh -J PROXY, as was answered by @Tomek, you can use ProxyJump and ProxyCommand in your ~/.ssh/config file to simplify connections on the command line. This has been covered elsewhere, including this post


I was having the same problem refer to this link

In simple terms do:

Net forwarding by net forwarding by uncommenting this line net.ipv4.ip_forward=1

Try ping the A system from B system and vice-versa. It will work

  • This is not the same problem at all. Private IPs are not Internet-routable. Even if routing were enabled on host B, it would not suffice. – Daniel B Apr 29 at 9:36
  • Ok @DanielB it working in my case. Sorry. – jkp Apr 29 at 10:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.