splitbrain.org

electronic brain surgery since 2001

Tunnel a local webserver to the Internet

Today at work I needed to test a locally installed webapp in a mobile browser. But our WiFi has no access to the local LAN for security reasons. The only way to access the Apache on my localhost would have been to try getting the VPN work on my phone. Too much hassle. Configuring firewall rules to have an exception for my host would have meant bothering our admin during his vacation. So that was out, too.

So what to do? Using a SSH Tunnel of course!

Here is what you need:

  • find a server with a public internet address (I used my own, eg. the one serving this website to you)
  • make sure it's firewall allows access to an unused port, eg. 9999
  • add the option GatewayPorts yes to your /etc/ssh/sshd_config and reload your SSH daemon1)

Got it so far? Then all you need to do on your local machine is running the following command:

ssh me@yourserver.com -R *:9999:localhost:80

Now you can reach your local web server on a public address. In the example above at http://yourserver.com:9999.

PS. a few weeks ago I read about a web service offering kind of the same thing. You just had to run a small utility provided by them and then could connect to one of their subdomains. Unfortunately I didn't bookmark it and now can't find it anymore. If anyone knows it, please let me know in the comments.

Tags:
linux, ssh, tunnel, webserver, howto
Similar posts:
1)
without this SSH will only bind to localhost on the remote server