I have 2 machines, A and B. Both of them are connected to their own wifi access point (routers). Both the wifi routers are connected to the same private LAN, like a university's intranet.

A's router has its public IP on the private LAN as and B's router has the IP Both A and B have their private IPs (wrt router) as Its obvious that more than 1 machine may be connected to each router, hence the solution should still allow this.

How do I ssh from A into B ?

How do I set up a simple P2P connection between the 2 machines?

Also if there is a 2nd machine on B's router, say C, how do I ssh to it from B? How do I ssh it from A, while simultaneously ssh-ing to B but from a different terminal window ?

  • By "a simple P2P connection", do you mean something different from ssh asked about in the previous sentence? If so, what? – bertieb Aug 30 '15 at 10:46
  • Try something like a client and echo-server using P2P – Codi Aug 31 '15 at 11:54

First thing you need to do is forward the ssh port (22 by default) on the server side so that when an incoming request on the router arrives, it will forward the request to the appropriate destination.

Then ssh to the public IP of the router (where the ssh server is connected).

In simple words, forward port 22 to the IP of your computer B on the router it is connected to. And use public IP of the router to connect to ssh.


What is the device that provides connection to both routers?

Use a different local IP range for your router clients so they don't conflict with other devices of the shared network.

Then, if both A and B can ping each others Local IP, then it works the regular way without any port forwarding.

ssh user@local-ip

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.