Every time I have either forgotten to forward a port over SSH, or needed to SSH into another machine first so I could find out what IP and port I needed to forward to, I have closed the SSH session and started a new one with the correct -L or -R option. After all these years I just found out that OpenSSH has a built in command line. I always knew about pressing ~. after a newline to close an SSH session, but didn't know I could use ~? to get a list of supported escape commands. One of those escape key sequences is ~C which brings up the openssh command line providing the following commands:

ssh> ?
      -L[bind_address:]port:host:hostport    Request local forward
      -R[bind_address:]port:host:hostport    Request remote forward
      -D[bind_address:]port                  Request dynamic forward
      -KL[bind_address:]port                 Cancel local forward
      -KR[bind_address:]port                 Cancel remote forward
      -KD[bind_address:]port                 Cancel dynamic forward

So for example if I want to add a forward for my local port 1032 to on the remote network I would type the following after a newline:

-L 1032:

and it would give a helpful little message saying Forwarding port.

It looks like this command line has been available in OpenSSH since at least version 3.2.2 from 2002, that's over 20 years ago! It also provides the ability to remove a forward using the KL, KR, and KD commands which can be useful if you need to point it at a new destination.

Previous Post Next Post