Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

From my computer (client) I can SSH connect to a server (host1) and from there I can SSH connect to another server (host2).

However I want to set up a dynamic tunnel between my client and host2.

I can dynamic tunnel from my client to host1 fine and I can dynamic tunnel from host1 to host2, but I can't seem to get the tunnel to be pointed from client to host2.

host1 and host2 are not on the same local network.

I can't connect to host2 from my client due to firewall on my network blocking custom ports, but I can connect to host1.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Set up a regular ssh tunnel to host1:

client$ ssh -L 1080:127.0.0.1:1080 host1

Then ssh from host1 to host2 and set up the proxy:

host1$ ssh -D 1080 host2

Point the browser's proxy config on client to localhost 1080.

share|improve this answer
    
Cheers, that got it working. I did originally try using -L but tried: client$ ssh -L 1080:host1:1080 host1 Using localhost works perfectly! :) ssh -L 1080:localhost:1080 host1 –  dan2k3k4 Oct 22 '11 at 19:07
    
ProxyCommand is a much better/cleaner solution –  JohnUopini Oct 22 '11 at 19:20
add comment

I would use the ProxyCommand option to spawn a netcat session between host1 and host2. On client you can do the following

$ ssh -D 1080 host2 -o 'ProxyCommand ssh host1 nc -w1 %h %p'

%h and %p are variables for hostname and portnumber. It is also possible to simply hardcode those values.

The -w option is to make netcat timeout when you are done. Without it you will leave dangling netcat sessions on host1. It is possible that that option varies between netcat versions.

Instead of having to run that long ssh command each time you can put something along these lines into your ~/.ssh/config

Host host2
  ProxyCommand ssh -e none host1 nc -w1 %h %p

Making it a simple mater of, on client, typing

$ ssh -D 1080 host2
share|improve this answer
add comment

Your Answer

 
discard

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.