Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a VM, accessible via 192.168.56.101:22. Now I want to create a tunnel:

127.0.0.1:12345 -> www.google.com:80

where 127.0.0.1 is the IP address of the loopback interface of the VM. The host OS has a route to www.google.com and no package forwarding enabled.

Is it possible to do this solely with SSH? If yes, how?

share|improve this question
    
I've assumed some stuff in my answer, if it's wrong let me know and I'll clarify. –  EightBitTony Jun 20 '11 at 20:23

3 Answers 3

up vote 3 down vote accepted

Try ssh -R 127.0.0.1:12345:www.google.com:80 username@192.168.56.101 from the host.

This will forward 127.0.0.1:12345 on the VM to www.google.com:80 over the tunnel.

share|improve this answer
    
Ah yes, I misread the query, the subtle difference between -L and -R is the key! –  EightBitTony Jun 20 '11 at 20:30
    
Great, thank you! –  Philip Jun 20 '11 at 20:48
ssh -L 127.0.0.1:12345:www.google.com:80 me@192.168.56.101

That creates the tunnel from some workstation, through 192.168.56.101 to www.google.com

I'm not sure your question is really asking that - but that's the answer that makes most sense. Since the VM can already reach www.google.com I'm presuming you've got a third machine (a workstation for example) that wants to reach google, via the VM.

But this creates a tunnel such that workstation is listening on port 12345, and any traffic sent to that port goes to your VM and then out to Google.

share|improve this answer
ssh  username@192.168.56.101  -L localhost:12345:google.com:80

Then, connect to localhost:12345 to access google.com. Also, you could use

ssh username@192.168.56.101  -D localhost:12345

to let ssh decide where to connect to (e.g. google.com:80) at the time that you connect to localhost:12345 with your application.

I believe either of those will do the trick.

share|improve this answer

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.