Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here's my scenario, I have two machines, A and B. A is behind a VPN, so B can't get to A. I have a web server:

machine_a$ curl localhost:8088 "hello from machine_a"

I have executed a remote SSH tunnel as follows:

machine_a$ ssh -R 8088:machine_a:8088 machine_b -N &

On machine B, I can verify that the tunnel is indeed open:

machine_b$ curl localhost:8088 "hello from machine_a"

How do I get machine_b to listen to HTTP traffic on 8089 and route/pipe/whatever into that locally available port 8088, which in turn is a remote port over to the HTTP server on machine_a?

(Also, I have setup a dummy server on machine_b:8089 and made sure that it is open.

share|improve this question
Not sure what you're talking about. You write "How do I get machine_b to serve HTTP traffic on 8089 and route/pipe/whatever into that locally available port 8088? nc, socat?" port 8088 is not available, it's being used by SSH. And if you sent HTTP traffic to that port as you want to, then if that sever on machine A:8088 is not an HTTP server and it looks like it's not, then I think you'll just get errors. And if you want do do HTTP through SSH then -L or -R won't do it unless you want only one website. You want -D. – barlop Jan 14 '13 at 21:03
Sorry, to clarify, the HTTP server lives on machine_a. I just want to setup a port (8089) on machine_b that proxies over to the locally bound port 8088 which is a ssh -R to machine_b 8088. Thus exposing the HTTP server that is behind the firewall. – weisjohn Jan 14 '13 at 23:23
OK so it's not for general browsing just to access the one HTTP server. Then yeah -L or -R would be for that.. ok – barlop Jan 15 '13 at 9:49
nc -l 8089 | nc localhost 8088
share|improve this answer
A little more explanation of what exactly is going on would be nice. – KronoS Jan 14 '13 at 20:28
@KronoS He asked "How do I get machine_b to serve HTTP traffic on 8089 and route/pipe/whatever into that locally available port 8088? nc, socat?" I'd say that line is fairly simple. Obviously listens on port 8089 and pipes that to localhost port 8088. That's what the guy asked for.I'd add that some nc versions might have to be nc -l -p, others might need to be just -l.There was quite a bit in the q about ssh so i'd have to think a lot, but,just looking at that little line there requesting how to do.. that answer answered it and the explanation is in the question i've quoted in this comment – barlop Jan 14 '13 at 20:50
of course, that server on port 8089 won't "serve http traffic", (which is what the questioner asked), it's not an http server, but I think the questioner might've just meant it gets sent http traffic. (I can't see how else the questioner can make any sense). It looks like @user... probably interpreted it right. – barlop Jan 14 '13 at 20:57
@barlop I'm just not a fan of the one line answers. If there was any more detail possible it would be nice. Also trying to encourage a new user to be as detailed as possible, even if the one line solves the issue. That's all. – KronoS Jan 14 '13 at 21:01
@barlop, yes. I did. The request is forwarded through the ssh tunnel to machine_a. The response came back through the ssh tunnel and was just directed dumped on the terminal. Which actually makes sense, because you're saying something of the manner of: netcat, listen on 8089 and pipe to (netcat, receive from stdin and send to localhost 8088) but the second netcat isn't directing it's output anywhere. – weisjohn Jan 16 '13 at 1:48
up vote 1 down vote accepted

With socat, this serves my purposes:

machine_b$ socat TCP-LISTEN:8089,su=nobody,fork,reuseaddr TCP-CONNECT:

This tells socat to listen on TCP port 8889 and connect it to local 8088. It runs as the nobody user, for better security. The fork option means that it will renegotiate the incoming port, so that it doesn't block.

cURLing from my machine:

my_machine$ curl machine_b:8089 "hello from machine_a"

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .