I am used to forwarding a remote service port on localhost using ssh like:

ssh -L 2181:localhost:2182 user@server (forward remote host port 2182 to local port 2181)

now, from the machine I ssh to, I am trying to reach a tcp service and forward the response to my local machine:

local-machine:2181 <-- SSH --> remote-machine:2182 <-- netcat/named pipe --> service:2181

Note: I do not have direct access to the service machine, I only have access to the network through the machine I SSH to.

I was trying to use netcat with a named pipe:

On the remote-machine:

mkfifo fifo
nc -k -l 2182 <fifo | nc service 2181 >fifo

On local machine: echo message | nc localhost 2181

but that doesn't seem to work.

I also tried, on remote-machine nc -k -l 2182 0<fifo | nc service 2181 1>fifo

without luck

On the remote machine nc -k -l 2182 outputs the message I send from the local-machine:2181

if I simply pipe this like: nc -k -l 2182 | nc service 2181 I do see the response from the service on the remote-machine. So I'm able to go all the way to the service and back to the remote-machine but it stops there:

local-machine:2181 <-/- SSH --> remote-machine:2182 <-- netcat --> service:2181

so I don't understand why the named pipe won't forward the response through the ssh connection back to my local machine.

echo message | nc localhost 2182 on the remote-machine does NOT output anything back on the local-machine, so it's not making it through SSH for some reason.

Any idea why this is and how to fix it?

Thanks for help.

closed as unclear what you're asking by Rui F Ribeiro, schily, G-Man, msp9011, thrig Aug 18 '18 at 14:38

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    I don't understand what you're trying to achieve. Are you tryint to do ssh -L 2181:service:2182 user@server? – ysdx Oct 6 '15 at 17:58
  • I cannot SSH to service directly, but I can SSH to the remote-machine that has access to the service. This is running in containers and I don't want to have a SSHD server in every container. I have a SSHD container that then is part of the network. I need to SSH to it and then proxy to the other services. – MrE Oct 6 '15 at 18:20
  • I see... I tried and it works. I always thought the localhost in that -L string was the local machine, not the localhost of the remote machine! – MrE Oct 6 '15 at 19:00

as pointed by @ysdx

the simple solution is:

ssh -L 2181:service:2182 user@server

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