Ngrok is one of the most popular tunnel service platform through which you can easily expose your local servers (like PWSLab installations) which are behind NATs/Firewalls to the public internet over secure tunnels.
It connects to the ngrok cloud service which accepts traffic on a public address and relays that traffic through to the ngrok process running on your machine and then on to the local address you specified.
Features of Ngrok
- You can instantly create a public HTTP/HTTPS URL for an application like PWSLab running locally in your server machine.
- Their tunnels are very fast and works on HTTP/2 protocol which actually speeds up your loading.
- You can even protect your tunnel with the help of HTTP Basic Authentication.
- With the help of web based portal, you can easily inspect (Request/Response) all the incoming traffic to your tunnel.
- You don’t need to do any kind of port forwarding while using Ngrok.
- You can even expose your network service to the internet with the help of TCP tunneling.
- Multiple simulatenously tunnels can be worked.
- Websocket support is also available.
How to setup install and setup Ngrok
Step 1 – Create a Free Account on Ngrok.com, basically you can create an account on Ngrok by three ways.
- With your personal Email
- With Github
- With Gmail
Step 2 – After confirming the account with your mail ID, just try to login with the same details which you’ve used while creating the account.
Step 3 – After successful signup, you’ll a Dashboard Page in front of you just like below:
– Now you need to download the Ngrok package from the Download
Based on your operating system, you can choose the file and ngrok supports all OS (Windows/Linux/MacOSX).
- Windows - For Windows 7, 8, 8.1 and 10
- Linux - Ubuntu, CentOS, RedHat
- Mac OSX
Use wget https://download-url/
if in case you are downloading Ngrok for a server edition of OS. You can copy the download url from the OS links in the Download
Step 5 – Next step is to install the package which you’ve downloaded from previous step.
- To extract the package in Linux/MacOSX – type “unzip /path/to/ngrok.zip” in your command terminal.
- And for Windows, just simply double click on the file and extract the .exe file with the help of Winrar/Winzip.
For Linux installations: Run apt-get install unzip or yum install unzip if unzip tool isn't installed.
Note: To use Ngrok, run CMD/Terminal/Bash from same directory where you’ve downloaded the Ngrok package.
Step 6 – Furthermore, you also need to connect to ngrok using a secure authtoken.
Run below command to add your account’s authtoken to your ngrok.yml file. Copy the token from the Dashboard as displayed in the screenshot above.
- For Windows - ngrok.exe authtoken <Your Token>
- For Linux/OSX - ./ngrok authtoken <Your Token>
Step 7 – Starting your first tunnel
Once you have your local server running, you can open a tunnel to the port where your application is running.
For local web server to internet, type the following in your terminal.
- For Windows - ngrok.exe http 80
- For Linux/OSX - ./ngrok http 80
Here you can see that, we’ve created a dummy index.php file into our xampp server which can easily be accessed on Internet with the help of Ngrok tunnelling address.
You can also inspect your all incoming HTTP traffic by using their web based portal which you can easily access by opening http://localhost:4040/ in your web browser.
To secure your tunnel you can use -auth switch which enables HTTP basic Auth security on all requests as shown in below command:
- For Windows - ngrok.exe http -auth=”username:password” 80
- For Linux/OSX - ./ngrok http -auth=”username:password” 80
Now, start sharing and accessing your Public URLs from the Internet with a single click!
To close the connection, simply close the terminal/CMD where the session is created.
Also, let us know if the article is helpful!