1

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.

2 Answers 2

2

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.

2
  • 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 Commented Oct 22, 2011 at 19:07
  • ProxyCommand is a much better/cleaner solution Commented Oct 22, 2011 at 19:20
2

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 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.