Situation:
Currently faces a situation where I had to showcase a use case locally developed on my personal machine to clients. In oder to achieve this had to expose my localhost services over the web so that it can be viewed.
Observations:
There are 2 solutions to exposing the local services using port forwarding.
1. Configure your router to open specific ports of your router a.k.a Port forwarding. Where in the router can be configured with opening the port of the router and exposing a specific port of your machine. This has some risks involved.
This option works best & without any dependency of other application. BUT if your are behind the carrier graded NAT (CGNAT) this is not an option for you as the ports are almost blocked by the ISP.
2. In order to overcome the issue with CGNAT the best solution that work is NGROK there are alternatives to it and can be evaluated on our requirement.
NGROK is a service which can be installed and ports can be exposed using a single command also you need to have a account created and use the AUTH-KEY. As per my requirement I was Abe to run the service as daemon thread and keep my services online till my system is working.
P.S : NGROK has different plans the free one suits the basic needs.
Solution:
1. Create an account on https://ngrok.com.
2. Once you have registered. Visit the dashboard where you can see the AUTH-KEY.
3. Visit the downloads link and download the application as per your system.
4. Once downloaded, unzip the file.
sudo unzip ~/Downloads/ngrok-v3-stable-darwin-amd64.zip -d /usr/local/bin
5. Add the AUTH-KEY to the config using the below command
ngrok config add-authtoken <token>
Note: Once you execute the above command a config file will be generated at the path /home/<user>/.config/ngrok keep a note as this will be used when we configure NGROK as a service.
6. Perform a quick check to verify the installation. run the below command.
ngrok http 80
Once you execute the command you will be provided with forwarding details and the temp URL. Same details will be visible in the online dashboard.
There is a local dashboard which can be accessed using below command or the browser.
curl localhost:4040/api/tunnels
7. The above setup works good in the foreground, let's create a service to run in the background.
8. Create a file ngrok.service in the directory /etc/systemd/system/ and updated the below config, note to update the path as per your system.
9. Run the below command to start & enable the service.
systemctl enable ngrok.service && systemctl start ngrok.service
10. Add the tunnels you need in the config file. as per below,
11. Visit the Dashboard to see all the services online and working.
Alernatives :
1. Localtunnel
2. localhost.run
0 Comments