It's Sunday morning and I'm trying to wrap my head around SSH and local port forwarding with the following two examples running on a machine with IP= to local port forward incoming connections on 1234 to port 5000 of another machine with IP=

Now I read the MAN page and saw examples on the net but one thing still isn't clear to me, namely: why does example 2 work?

1: (shell prompt for clarity) okihara$ ssh -nvNT -g -L 1234: localhost

and 2: okihara$ ssh -nvNT -g -L 1234:localhost:5000 okihara@

Example #1 seems rather self-explanatory, ie. login to the remote ssh is not needed and as such, I could local port forward to, eg. www.w3.org:80, but example #2 is a bit obscure to me.

  • Said another way.... The localhost in -L 1234:localhost:5000 in Example 2 is While the localhost in example one is – Eddie Dunn Nov 22 '15 at 21:01

You examples have few problems

  • In the codes, you are using -L switches, which are for Local Port Forwarding
  • The localhost in argument is meant relative to the respective host (remote host for local forwarding and your local machine for remote port forwarding). Specifying something else then localhost allows to bind outer network interfaces and also remote machines in one or the other network,

If it still didn't answer your question, please update your answer accordingly and make sure your used terms (local, remote) and commands are used accordingly.

  • My bad, I did mean local port forward. I do understand example 2 now. Still, is there any way to achieve the same with remote port forward? – VH-NZZ Nov 23 '15 at 8:39
  • remote port forward is reverse of the local port forwarding. This means that it is used for tasks from the other side. You can achieve almost the same thing by issuing the command from the other host, if they are both resolvable from each other. – Jakuje Nov 23 '15 at 8:44

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.