Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .