Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ssh double tunneling

365 views
Skip to first unread message

Norman

unread,
Jun 20, 2009, 4:00:29 PM6/20/09
to
Hello, here is what i have:

laptop -> server-1 -> server-2

from my terminal i would like to say for example run:

$python
>>> import urllib2
>>> request = urllib2.Request('server2')
etc..

the problem is that only server1 is allowed to talk to server-2

is there a way to 'double' tunnel from laptop and execute my python
code and for server-2 to respond?

thanks

Piet van Oostrum

unread,
Jun 27, 2009, 8:42:32 AM6/27/09
to
>>>>> Norman <norman...@gmail.com> (N) wrote:

>N> Hello, here is what i have:
>N> laptop -> server-1 -> server-2

>N> from my terminal i would like to say for example run:

>N> $python


>>>>> import urllib2
>>>>> request = urllib2.Request('server2')

>N> etc..

>N> the problem is that only server1 is allowed to talk to server-2

>N> is there a way to 'double' tunnel from laptop and execute my python
>N> code and for server-2 to respond?

You don't need double tunneling. Just a normal ssh tunnel is sufficient.

I suppose both servers are in the domain example.com.

set up ssh tunneling from your laptop to server1 like:

ssh -L 8000:server2.example.com:80 server1.example.com

so port 8000 on your laptop is now forwarded from server1 to server2
port 80.

headers = {'Host': 'server2.example.com'}
url = 'http://localhost:8000'
req = urllib2.Request(url, None, headers)
r = urllib2.urlopen(req)
data = r.read()

You could even setup the ssh tunnel from your python program with
paramiko:

http://bazaar.launchpad.net/~robey/paramiko/trunk/annotate/head%3A/demos/forward.py
--
Piet van Oostrum <pi...@cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: pi...@vanoostrum.org

0 new messages