Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

I have the following scenario:

  1. A service listening on port 6678 on Computer C
  2. Only computer B can access computer C via ssh
  3. Computer B is accessible globally

I would like to do the following:

Setup a service on a Computer "A" that listens on port 6678 that would end up being redirected to computer "C" and to its listening service. I understand that I need to create an SSH tunnel through multiple hops. Such as A -> B -> C.

This question helped me a lot, but the problem is: It does not set a socket on "A" that may be accessed globally. I tried to mess around with ssh -D to set a binding socket, e.g.

ssh -D *:6678 -p 6678 localhost

but it does not seem to do a trick.

What would be the best option for creating a multiple-hop SSH tunnel and at the same time setup a listener on computer "A" to allow traffic to?

share|improve this question

I think you are looking for:

ssh -g -L 6678:computerC:6678 computerB

If you run this on computer A it will open a port on computer A and traffic will be redirected to computer C using the ssh connection to computer B. This assumes that computer B can access port 6678 on computer C directly. You may want to try this without the -g option first if you only need access to computer C from computer A. If you need to grant access to computer C to multiple machines you will need the -g options and possibly and adjustment to your firewall rules.

share|improve this answer
To set this up as a service, autossh can help by automatically restarting ssh if the tunnel should stop passing traffic. – Andrew Schulman Nov 16 '11 at 15:10
I haven't heard of autossh before. Would be a good idea since I have seen port scans kill ssh port forwarding. – chuck Nov 16 '11 at 16:33
I use daemontools to auto-restart my SSH tunnels, same idea, very handy. – mikebabcock Jul 6 '12 at 13:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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