9

So this works for me:

ssh -v -L 8080:remotewebserver:8080 me@jumphost

How about if I would also like to include more ports?

I want to forward not only 8080, but also 8443, 8923 and 8181?

Do I need to do a new connection for each port?

17

No, you do not need one connection per forwarded port, just add further -L statements:

ssh -L LPort1:RHOST1:RPORT1 -L LPORT2:RHOST2:RPORT2 me@ju.mp.ho.st

This can be shortened to ssh jump, using the "alias" jump, if you set up a matching section in your ~/.ssh/config like this:

Host jump
    User myUserName
    Hostname ju.mp.ho.st
    Port 2345
    LocalForward 8080 remotewebserver:8080
    LocalForward 8443 remotewebserver:8443
    LocalForward 8923 remotewebserver:8923
    LocalForward 8181 remotewebserver:8181

# Eliminates reconnection delay, and does not try to re-forward ports:
Host *
  ControlMaster auto
  ControlPath /tmp/%r@%h:%p

I have used this technique for many years, surely already with 10+ ports, but when I need more ports forwarded, I use Dynamic Socks Proxy support -D.

  • 1
    When connecting, I would see these error messages for each forwarded port: bind: Address already in use channel_setup_fwd_listener_tcpip: cannot listen to port: then Could not request local forwarding. With the Control* settings, these are gone, thanks! PS: I've been using that comment flag a lot on SE, and you're the first other person I've seen also using it. Appreciate that :) – Dan Dascalescu Jul 4 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.