There are third party websites available to expose localhost to the internet. But in this post I will explain how we can do it via our own SSH server.
While working in an organization and at the time of development we always need to expose localhost to the internet for sharing things of local computer to the remote users. Most of organizations have at-least one server so Let’s learn how we can expose localhost to the internet via our server using SSH.
People also use “ngrok” for the same purpose but using this we can not modify the ngrok subdomain if we do not buy a premium service.
To get started we will need the following requirements to expose the localhost via a server.
1 – A Server which can be connected through SSH client.
2 – A SSH client like putty or mRemoteNG. I recommend using mRemoteNG as it is multi threaded which will be faster than putty.
3 – A TCP port on the server which is not in use. In this post I will use port 5000 of the SSH Server and 80 of the localhost. Please make sure your server’s firewall allows the port for inbound connections.
For exposing localhost first open mRemoteNG. Install mRemoteNG with default settings.
Now in the connect section enter the IP address of your server. As shown in the picture.
Select SSH2 next to the connect section.
Then click on SSH2 to connect.
Now enter your server’s username and password or if you are using the public key for authentication then you will not need username and password. You can log in direclty with that key.
After that you will see the following screen after successful login to the server.
Now right-click on the tab and select “putty settings” as shown in the picture.
Then it will open settings screen. Go to Connections — SSH — Tunnels.
Then in the Source Port section add the port of the server which you need to forward to the localhost. e.g. 5000
And then in the Destination section add “localhost:80“. Change the port 80 according to your need many be your TCP program or site is running on different port.
Select “Remote” below the destination.
And finally click on the “Add” button.
After pressing add button your putty settings screen will look like this.
After that click on the “Apply” button.
Now your server is forwarding it’s port 5000 to the port 80 of your localhost machine.
You can access it with server-ip-or-domain:5000 from the internet and you will see the output of localhost:80.
Note: Keep open the connection tab until you want to keep on the port forwarding.
Also read – How to host Django with IIS.