I have a web server running on a local machine and it is easily accessible to all machines on the LAN. I also have a remote server with a public IP address/URL pointing to it (example.com). I cannot access my local server from outside of my network because I'm stuck behind my ISP's NAT (they won't grant public IP or port forward anything), so I'm trying to configure a reverse SSH tunnel to grant public access.

I am running ssh -R 8080:localhost:80 [email protected] -i $SSH_KEY -N on the local server to try to create the tunnel.

Using eLinks on the remote server, I can access, and it correctly displays the sites on the local server. However, visiting example.com:8080 in the browser does not show anything. I've tried using local port forwarding to redirect incoming traffic to but that doesn't work. Any other ideas to redirect incoming traffic from a web browser into my SSH tunnel?

1 Answer 1


-R 8080:localhost:80 is usually not enough. See man 1 ssh [emphasis mine]:

-R [bind_address:]port:host:hostport

Specifies that connections to the given TCP port or Unix socket on the remote (server) host are to be forwarded to the local side.


By default, TCP listening sockets on the server will be bound to the loopback interface only. This may be overridden by specifying a bind_address. An empty bind_address, or the address *, indicates that the remote socket should listen on all interfaces. Specifying a remote bind_address will only succeed if the server's GatewayPorts option is enabled (see sshd_config(5)).

Your tries with on the server indicate the listening socket is bound to the loopback interface. Most likely it is not bound to any other interface.

You need to explicitly specify bind_address or to use * or to use an empty string as bind_address. The option with an empty bind_address looks like this (note the leading :):

-R :8080:localhost:80

Additionally the state of GatewayPorts in the sshd_config on the server is important. From man 5 sshd_config:


Specifies whether remote hosts are allowed to connect to ports forwarded for the client. By default, sshd(8) binds remote port forwardings to the loopback address. This prevents other remote hosts from connecting to forwarded ports. GatewayPorts can be used to specify that sshd should allow remote port forwardings to bind to non-loopback addresses, thus allowing other hosts to connect. The argument may be no to force remote port forwardings to be available to the local host only, yes to force remote port forwardings to bind to the wildcard address, or clientspecified to allow the client to select the address to which the forwarding is bound. The default is no.

To achieve what you want the option must not be no. Note no is the default value, so unspecified GatewayPorts still means no. The value of yes will make -R 8080:localhost:80 work like -R :8080:localhost:80.

I advise GatewayPorts clientspecified in the server config and ssh -R :8080:localhost:80 … on the client.

After changing the config file you need to restart the SSH server or otherwise tell it to reload the configuration. sshd from OpenSSH rereads its configuration upon receiving a hangup signal, SIGHUP.

Possible additional problems:

  • 1
    Ok, that actually makes sense, preventing outside connections by default. By setting GatewayPorts and passing an empty bind-address, the local address of netstat -an changed from to, so it looks like that should accept traffic from any source, right? It still fails to connect from my web browser, but if I try to connect and check netstat again, I see a bunch of entries that show the IP I'm connecting from, but with a TIME_WAIT status instead of LISTEN or ESTABLISHED. Jul 7, 2020 at 22:13
  • So it didn't work yesterday, but when I opened it up to play around some more, it ended up working today! Thanks again for those tips, I guess something must've restarted or updated overnight and fixed whatever was the problem. Jul 8, 2020 at 21:34

You must log in to answer this question.

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