sshportportforwarding

ssh -L forward multiple ports


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?


Solution

  • The -L option can be specified multiple times within the same command. Every time with different ports. I.e. ssh -L localPort0:ip:remotePort0 -L localPort1:ip:remotePort1 ...