ssh -L forward multiple ports

PascalVKooten picture PascalVKooten · Apr 29, 2015 · Viewed 81.6k times · Source

I'm currently running a bunch of:

sudo ssh -L PORT:IP:PORT root@IP

where IP is the target of a secured machine, and PORT represents the ports I'm forwarding.

This is because I use a lot of applications which I cannot access without this forwarding. After performing this, I can access through localhost:PORT.

The main problem occured now that I actually have 4 of these ports that I have to forward.

My solution is to open 4 shells and constantly search my history backwards to look for exactly which ports need to be forwarded etc, and then run this command - one in each shell (having to fill in passwords etc).

If only I could do something like:

sudo ssh -L PORT1+PORT2+PORT+3:IP:PORT+PORT2+PORT3 root@IP

then that would already really help.

Is there a way to make it easier to do this?

Answer

NaN picture NaN · Apr 29, 2015

The -L option can be specified multiple times within the same command. Every time with different ports.