How do I send requests to a private network?

I’m trying to connect to a NodeJS server I wrote in my school network from home so I can work on it. However it’s behind a router firewall I have no access to. Is there any way I can make my server accessible from the outside so I can make requests from it?

I was considering some kind of socketed connection where my server tries to “reach out” to my home network every second to establish a link which we can use, but I’m not sure that’s feasible or even the best way to go about it.

Answer

Let A be your school server, B your home server, A_user your username on A, and B_user resp. on B.

On B: assuming you are running linux, ensure you have openssh-server installed and running.

On A:

ssh -R 10022:localhost:22 B_user@B

This establishes an ssh connection to your server at home and open a reverse tunnel. This tunnel means that any connection on B’s port 10022 will be forwarded over that first ssh connection to A’s port 22 (ssh).

Now on B:

ssh -p 10022 A_user@localhost

This should give you the idea. In practice, you will find that that ssh tunnel will stop working every once in a while. Once you are ready for it, look at autossh to keep it alive and reestablish it automatically if necessary.