I have a server machine (A) which has ssh installed, along with a webserver.

How do I forward the port with the webserver to my local machine (B).

I should be able to browse to http://localhost:forwardedport

Is this LOCAL or REMOTE port fowarding? Here's what I've tried.

ssh -L 8888:name.dnydns-server.com:8888 localhost

ssh -L 8888:localhost:8888 name.dnydns-server.com

and both of those with username@name.dnydns-server.com

What am I doing wrong?

EDIT: The answers given were factually correct and explained the usage of port forwarding. It turned out that I was using the correct command, rather there was a firewall rule which prevented me from connecting to port 8888 FROM the server itself. I figured this out when I tried to connect to the website while sshed into the remote server.

  • you need to do some troubleshooting. check it Prior to doing http:// localhost. Was the SSH tunnel created? The command netstat -aon should show you. Maybe the tunnel isn't getting created because of the windows firewall blocking port 22 at the machine running sshd. Paste what results you get when you run that ssh command in the command line. Show what happens when you do http ://localhost
    – barlop
    Oct 29, 2013 at 21:56
  • For me portforwarding means setting the router to point incoming traffic on a certain port (say 80 for http) to a specific computer/server in the network. You ask about ssh tunnels. But maybe I misunderstand?
    – SPRBRN
    Oct 30, 2013 at 10:54

2 Answers 2


I guess you first need to get clear on some terms I'll use:

Client means the machine where you start ssh. This machine is refered to by "local".

Server means the machine you want to connect to with ssh. This machine is refered to by "remote".

Local port forwarding with ssh means you connect from your client to your server and thereby open a tunnel so that another program on your client can connect via a local port to a host&port on the server site. The option for this is -L local_port:remote_machine:remote_port.

Remote port forwarding with ssh means you connect from your client to your server and thereby open a tunnel so that a program on your server can connect via a port on the server to a host&port on the client site. The option for this is -R remote_port:local_machine:local_port.

If I understand you correctly, you want a local forwarding, e.g. create a connection to your server name.dnydns-server.com and then connect with your local browser to port 8888 on name.dnydns-server.com.

The following command from your list should actually do what you want:

ssh -L 8888:localhost:8888 name.dnydns-server.com

The first 8888 is the port on your client that your additional program (browser) can connet to.

The "localhost" in that line is seen from the end of the tunnel, that is on the server (name.dnydns-server.com). There localhost is the machine itself so it's the one you want. (You could place a different name on the network of your server there to access that)

The second 8888 is the port you want to connect to on the server site. If you run your webserver on the standard port 80, you'll have to change this to 80.

name.dnydns-server.com is the name of your ssh server where you connect to, which is then the endpoint of the tunnel.

I don't know why this line didn't work for you though. Did you quit the ssh? It has to stay connected the whole time for the tunnel to work. Default port on the webserver? Webserver not running?

Edit: I changed the definition of "client" and "server" to clarify things, so some of the comments don't apply anymore and refer to deleted content.

  • good you started with definitions. If the situation were different and you were running the ssh server at the machine that you sit at, then what terminology would you use? (though I am not sure of when such a user case would happen)
    – barlop
    Oct 29, 2013 at 20:50
  • also, i'm curious, can you outline an example of where this isn't so- "Client means the machine you sit at (usually - if you chain connections it could be more complicated)"?
    – barlop
    Oct 29, 2013 at 20:55
  • You could sit at machine A, do "ssh B" and then "ssh C" from there. For the second ssh, the "client" is B, not the machine you sit at. Oct 29, 2013 at 21:29
  • ok, and how would you connect the two tunnels the A-B tunnel and the B-C tunnel?
    – barlop
    Oct 29, 2013 at 21:50
  • 1
    something like this should work: ssh -L 8888:localhost:9999 B "ssh -L 9999:localhost:7777 C" - but that wasn't really what I thought about when I made my definitions. There are other scenarios, where you don't sit at the ssh-client, like remote desktop connections. Oct 29, 2013 at 22:34

I am presuming that the server has sshd installed, and listening on the well known default port (22), and that the web server is listening on the well-known default port (80). The assumption is that the server is the server (A) is the 'conduit' through which you want to tunnel to get to the web server. Here's what you need to 'tell' ssh in this case:

ssh -L <local port to point your browser toward>:<host name or IP of the web server>:<port that the web server is listening on> <valid user on server>@<server name or ip address>

So, here's what I think it should look like based on what I think you're trying to do:

ssh -L 8888:web.server.dyndns-server.com:80 youruserid@yourserver

Do this, then point your browser to localhost:8888.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.