In our fifth post of the “Fortifying Your Digital Fortress” series, we explore Ngrok, a dynamic tool that enables secure and seamless access to local servers and services from anywhere on the internet. Ngrok’s tunneling capability creates a secure link between external users and private network services, perfect for securely testing, sharing, and accessing resources on a local system. Understanding Ngrok is essential for network administrators, developers, and cybersecurity professionals looking to enable secure, temporary access to local environments without extensive firewall or network configurations.
In this article, we’ll cover:
- An introduction to Ngrok and its key functionalities.
- Setting up and configuring Ngrok on a local server.
- Securing network access using Ngrok’s tunneling.
- Practical use cases for Ngrok in testing and secure remote access.
Introduction to Ngrok: Simplifying Network Access
Ngrok is a reverse proxy tool that creates secure tunnels from the internet to localhost, enabling users to access a local web server or API service from a remote location. Its key feature is the ability to generate a public-facing URL that redirects to a local server. This URL can then be shared to allow access to specific services running on a private network.
Key Features of Ngrok
- HTTP/HTTPS Tunnels: Expose web services with secure and customizable URLs.
- TCP Tunnels: Useful for secure access to non-HTTP services, such as databases.
- Session Inspection: View real-time session details to monitor traffic and status.
- Web Interface: Ngrok’s dashboard provides access to logs and request details for all active tunnels.
- Encrypted Tunnels: Data transmitted through Ngrok is encrypted, enhancing security.
Setting Up Ngrok on a Local Server
Step 1: Installing Ngrok
Ngrok can be installed on various operating systems, including Windows, macOS, and Linux. To start, download Ngrok from the official website.
- Download: Select the version compatible with your OS.
- Unzip: Extract the downloaded file to a preferred directory.
- Access Token: Create an Ngrok account to obtain an authentication token, which enables you to run secure tunnels.

Once downloaded and extracted, Ngrok is ready to use via the terminal. Use the following command to add your access token:
./ngrok authtoken YOUR_AUTH_TOKEN

Step 2: Starting a Local Web Server
To demonstrate Ngrok’s tunneling capabilities, set up a local web server using Apache or Python’s simple HTTP server.
- Install Apache: If you’re on Linux, install Apache using:
sudo apt update
sudo apt install apache2

- Verify Server: Once installed, start the server and verify that it’s running by navigating to
http://localhost:80.
sudo service apache2 start

- Prepare Content: Place an HTML file in the server’s root directory (
/var/www/html/) to serve as the webpage accessible via Ngrok.


Step 3: Creating an Ngrok Tunnel to Your Local Web Server
Now that the web server is active, you can use Ngrok to expose it to the internet.
- Start Tunnel: In the terminal, navigate to the directory containing Ngrok and start a tunnel to your local server’s port (e.g., port 80 for HTTP).
./ngrok http 80
- Note the Public URL: Ngrok will generate a secure public URL (e.g.,
http://abcd1234.ngrok.io) that you can use to access the local server from any internet-enabled device.

Securing Network Access with Ngrok
Ngrok’s tunneling makes services accessible to the internet, so implementing security is crucial, especially for sensitive environments.
Authentication with Access Control
Ngrok supports basic HTTP authentication for tunnels, restricting access to users with valid credentials. Add the following command when launching Ngrok to require a username and password:
./ngrok http -auth="username:password" 80

Configuring Access Control with Firewalls and IP Whitelisting
For enhanced security, configure your firewall to only allow connections from specific IP addresses. This can be managed on your local router/firewall or via Ngrok’s paid plan, which includes IP whitelisting features.
- Local Firewall Rules: Configure rules to only accept connections from trusted IP ranges.
- Ngrok IP Whitelisting: For business accounts, Ngrok provides advanced access controls, including IP filtering.
Secure Connections with HTTPS
Ngrok generates HTTPS URLs by default, ensuring data is encrypted. This is particularly important for protecting sensitive information and preventing eavesdropping.
- HTTPS by Default: The
https://URL provided by Ngrok encrypts data in transit. - Custom Certificates: If you need to use your own SSL/TLS certificates, Ngrok allows for custom domains and certificates with premium plans.
Practical Use Cases for Ngrok in Penetration Testing and Network Security
Ngrok’s flexibility makes it suitable for a variety of security tasks, from penetration testing to remote access and secure API development.
Exposing Local Servers for Remote Testing
Ngrok can make local services accessible for remote testing, a valuable feature for developers and security teams who need to share their progress without deploying on a live server.
- Web Applications: Expose a web app hosted on a local server to external clients for testing.
- API Endpoints: Share locally hosted API endpoints with external applications or developers.
Mobile Testing and IoT Device Access
Accessing and testing IoT devices, routers, or mobile applications that connect to a local server is simplified with Ngrok. Instead of setting up complex routing configurations, you can use Ngrok to make these services accessible from a remote device.
- Mobile App Testing: Use Ngrok to connect a mobile app to a locally hosted backend API.
- IoT Device Debugging: Access and troubleshoot IoT devices remotely by connecting them through Ngrok.
Penetration Testing with Ngrok
Penetration testers often use Ngrok to quickly expose vulnerable services for controlled exploitation. Ngrok simplifies the setup process, making it easy to test applications in a safe environment.
- Remote Access Testing: Test services from a remote location to assess exposure risks.
- Vulnerability Identification: Use Ngrok to expose vulnerable applications to security tools like Metasploit for controlled testing.
Secure Tunneling for SSH and Remote Desktop
Ngrok can forward SSH and Remote Desktop connections, allowing secure access to a computer or server’s command-line interface from a remote location.
- SSH Access: Forward SSH traffic by creating a TCP tunnel with Ngrok:
./ngrok tcp 22
- Remote Desktop Protocol (RDP): For Windows users, forward RDP traffic by specifying the default RDP port (3389)
:
./ngrok tcp 3389
Configuring Ngrok for Apache Web Server Access
Step 1: Set Up Apache to Listen on a Non-Default Port
To run multiple services concurrently, configure Apache to listen on a different port, such as 8001.
- Edit Apache Ports File: Open the Apache configuration file for ports:
sudo nano /etc/apache2/ports.conf
- Specify the Port: Add the following line to make Apache listen on port 8001:
Listen 8001
- Restart Apache: Apply the new configuration:bashCopy code
sudo service apache2 restart
Step 2: Create a Tunnel to the Specified Port
With Apache configured to use a new port, start a tunnel with Ngrok to forward traffic from port 8001.
./ngrok http 8001
Ngrok will provide a new URL, allowing external access to the web server running on port 8001.
Monitoring and Managing Ngrok Sessions
Ngrok’s web interface provides detailed insights into each active session, making it easier to monitor and manage network traffic.
Using the Ngrok Web Interface
- Open the Dashboard: Access the dashboard at
http://127.0.0.1:4040. - Inspect Requests: View detailed logs, including request headers, response status, and payloads.
- Replay Requests: Resend previous requests to test how your server handles repeated connections.

This interface is especially useful for debugging and observing how Ngrok routes traffic to your server.
Session Termination and Security
When a session is complete, remember to end it by closing the Ngrok terminal. This prevents unintended access and ensures that your server is not exposed longer than necessary.
- Terminate Tunnels: Use
Ctrl + Cin the terminal to stop Ngrok. - Automatic Session Expiration: Ngrok sessions expire periodically, enhancing security by closing tunnels when not in use.
Conclusion: Enhancing Security with Controlled Exposure Using Ngrok
Ngrok is a versatile tool that balances accessibility and security, allowing users to share services without compromising their network. By using Ngrok’s tunneling features with authentication, encryption, and access controls, you can safely expose services to the internet for testing, collaboration, or troubleshooting. Understanding how to leverage Ngrok in a secure manner contributes to a well-rounded digital fortress, allowing users to access internal resources safely while mitigating exposure risks.
In the next post in the “Fortifying Your Digital Fortress” series, we will delve into deploying Kali Linux on Amazon Web Services (AWS). Hosting Kali Linux in the cloud with AWS offers flexibility and scalability for cybersecurity tasks, from penetration testing to ethical hacking, without compromising your local system’s security.
FAQs
What is Ngrok used for in cybersecurity?
Ngrok is a powerful tool used in cybersecurity to create secure tunnels that allow users to expose local services to the internet safely. It provides a reverse proxy for web servers, enabling developers and security professionals to test and share applications without deploying them on a public server. By generating public-facing URLs for local applications, Ngrok supports secure testing, API development, and remote access for penetration testing. Its features, such as session inspection and TLS encryption, make it particularly useful for monitoring network traffic, identifying vulnerabilities, and ensuring that sensitive information is transmitted securely.
How do I secure Ngrok tunnels with authentication?
To secure Ngrok tunnels with authentication, you can implement basic HTTP authentication by specifying a username and password when starting the tunnel. This adds a layer of security, ensuring that only users with valid credentials can access the exposed service. To set this up, launch Ngrok with the -auth flag followed by your desired username and password in the following format: ./ngrok http -auth="username:password" 80. This command will require anyone attempting to access the Ngrok URL to enter the correct credentials, thus restricting access to authorized users only. Additionally, it is advisable to regularly update your credentials and utilize strong, unique passwords to enhance protection further.
Is Ngrok secure for exposing local servers?
Ngrok is generally considered secure for exposing local servers when used correctly. It provides encrypted tunnels, ensuring that data transmitted between the local server and external users is protected from eavesdropping. Additionally, Ngrok supports features like basic HTTP authentication and IP whitelisting, allowing users to implement access controls to restrict who can access the services. However, it is essential to properly configure these security measures and to be cautious when exposing potentially sensitive services to the internet. By following best practices and utilizing Ngrok’s security options, users can safely expose local servers for testing and development while minimizing risks.








