Consider the following situation:
At my home, I have a router (which is connected to internet), server (S) and my main machine (M). S is reachable from the internet (it has static IP), and it is up 24/7, while M is not.
Sometimes, I want to make some app (which listens on some port on M, for example 8888) accessible from outer internet.
For that, I wanted to set up some port on S (2222) to forward to M's port 8888, so that anybody accessing S:2222 would feel like he was accessing M:8888.
I tried to use ssh port forwarding, my best attempt was as follows:
ssh -L 2222:M:8888 -N M
But that only allows me to access 2222 port from server itself, not from other machines.
Is there some way to do it properly? Preferably, I'd like it to be a simple command, which I would be able to start and shut down with ^C when I don't need that forwarding anymore.