This is actually pretty easy to accomplish, even though it's somewhat buried in the ssh documentation. Assuming OpenSSH, the basic syntax is as follows:
ssh -R 8080:localhost:80 -N username@your-server.dyndns.org
This will open a listening socket on port 8080 of your-server.dyndns.org, and any connections that are made onto your-server.dyndns.org:8080
will be forwarded over the SSH tunnel to the computer which has opened that SSH connection, and from there will be directed to localhost:80
.
The -N
option instructs SSH not to open a shell or whatever, just to establish the port forwarding, so you can send it into the background and leave it running.
Putty uses pretty much the same syntax, but wrapped into some sort of GUI. The principle is the same though.
But be careful in what you do. Since you're essentially funneling external traffic into your network, you are pushing a hole in your network's firewall. If it is not your network, your admin may object to this and take you responsible—usually there is a reason why you are not allowed certain kinds of traffic.
1no its just my home network but and im using ssh on a mac which i think is an implimentation of openssh code but going to mysite.com:8080 is giving an error of a nonexistant server, i check with telnet and it says there nothing – Trevor Rudolph – 2012-12-10T02:06:22.780
but i just checked on the remote computer and it says this,
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 0 14875755 -
– Trevor Rudolph – 2012-12-10T02:07:35.773How exactly does your commandline look like? The
localhost:80
part is the crucial thing here—it has to exist from the point of view of your local computer, not of the remote one, otherwise you'll get errors like the above. – Vucar Timnärakrul – 2012-12-10T02:15:11.840yea i wrote in 127.0.0.1 instead, ill try localhost... – Trevor Rudolph – 2012-12-10T02:25:36.480
nope, just tryed
macbookpro:~ trevor$ ssh -R 8080:localhost:80 -N root@blank.com
and it didnt work on the other side trting to access 8080 let me check portforwarding on the remote router – Trevor Rudolph – 2012-12-10T02:27:47.8331It seems as if the remote side only binds on localhost instead of to all interfaces. Try doing it this way:
ssh -R *:8080:localhost:80 -N ...
, that way you're telling it to listen on port 8080 on all network interfaces that are in reach. The line above worked on my PC, but maybe the Mac version of ssh works slightly differently. – Vucar Timnärakrul – 2012-12-10T02:28:03.800In any case, try adding
-v
to your ssh commandline, then you see more about what's going on and how exactly ssh is building the wrong kind of tunnel. Look for lines likeRemote connections from LOCALHOST:19050 forwarded to local address localhost:22
. – Vucar Timnärakrul – 2012-12-10T02:30:44.797this is what you mean
debug1: remote forward success for: listen 8080, connect localhost:80
– Trevor Rudolph – 2012-12-10T02:37:55.730It seems to be set up correctly. When you try to connect to this, what exactly do you do, and what exactly is your error message? Are you sure that there is no firewall blocking port 8080 on the remote end? – Vucar Timnärakrul – 2012-12-10T02:46:06.630
Another thing: You most likely do not want to build your reverse tunnels as root if not strictly necessary, especially as you maybe will leave your tunnel running once it works. – Vucar Timnärakrul – 2012-12-10T03:02:17.683
well even if i set up the tunnel and run
curl http://127.0.0.1:8080
over ssh it doesnt put out the "Hello" its suposed to but it just stays delayed for ever – Trevor Rudolph – 2012-12-10T04:05:05.667OH MY GOD IT WORKED NEVER MINE HAHAHA – Trevor Rudolph – 2012-12-10T04:07:00.827