I have a client running in a PC_A (PC_A is connected in a LAN hence having a private IP)

I have a server running in a PC_B (PC_B is connected in a LAN hence having a private IP)

==> I want to make a connection between PC_A and PC_B, which I cannot directly since they have private IPs.

I thought of using tunneling through SSH using a third PC_C, with a known public IP, to act as a bridge or a relay to connect both of them under TCP.

Would you please explain the setup of SSH and the command lines I should run in each machine please?

By the way, I am using Windows platforms.

Thanks in advance :)

  • It should be asked on Super User, Server Fault _ and similar. This section is about _Unix and Linux . – fugitive Jan 24 '18 at 21:56
  • What are private IP for you? Because two hosts with private IP (in their official meaning, like can certainly communicate among them. Also, by definition, all hosts are connected in a (W)LAN. – Patrick Mevzek Jan 24 '18 at 22:00
  • Usually folks will use some kind of a VPN to pull this off. There are VPN appliances which will make this dead easy if you don't want to roll your own. (Assuming that the LANs are not in the same location). – 111--- Jan 24 '18 at 22:00
  • What I mean here is that PC_A is connected in a company's network. Lets call the 1st network of company A LAN_A & the other host, PC_B, is connected in another company's network. Lets call the 2nd network of company B LAN_B meaning that they r in different LANs. The issue is that all the machines in each company have private IPs yes, but all of them connected to the external world through one single public IP. So, trying to access one PC from another using IPs wont work especially that both companies use firewalls. – Centaure Jan 25 '18 at 15:22
  • I thought of using SSH tunneling to by pass the firewalls using a third public machine to act as a relay and use SSH for that. Any inquiries please? – Centaure Jan 25 '18 at 15:24

You need a third server that is reachable by ssh from PC_A and that in turn can reach PC_B; let's call it PC_G (for Gateway).

In your $HOME/.ssh/config on PC_A put this:

Host PC_B
  ProxyCommand ssh PC_G nc -w 120 PC_B 22

Now, if you execute ssh PC_B on PC_A, ssh looks up the config for PC_B, and sees that the specified proxy command has to be run. So it runs ssh PC_G nc -w 120 PC_B 22 which starts the command nc -w 120 PC_B 22 on PC_G. This is the netcat command, opening a connection to PC_B port 22 (the ssh port). Now the local ssh can connect via this tunnel to the ssh client on PC_B.

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.