How to Expose Traffic to Internet without Public IP?

Abhishek Sahu
4 min readOct 23, 2021

Hello readers, Welcome back to our blog. Today we are going to talk about exposing a traffic to a port or a container or an instance(VM) without an public IP address. To achieve this we are going to use a ngrok tunnel.

source: www.ngrok.com

Let’s understand What is tunnel?

In general we know tunnel as a passageway which let us in from one point and exit to another point, the exit of these tunnels may be a public place or a secret cave full of treasure. Similarly a virtual tunnel provides a way to enter from a public URL to our private environment or our local machine.

What is the benefit of tunnels, Why to use Ngrok tunnels?

Basically tunnels provides us a direct access to any system, and we can expose any port on our local machine or more clear Isolated machines. We can use tunnels to expose SSH, http/s, or any tcp traffic. We can use it to host content or ssh inside containers without public IP, We can use it for hosting content from our local machines, etc.

Today, we are going to host a website from a docker container without exposing any ports publicly.

For this practical you must have docker install and running on your system.

Step 1: Launch a docker container of any image, I am using CentOS

Launching a CentOS container

Here we are using -it flag to launch container in interactive terminal mode, basically it will give us a bash shell inside these container, you can also see that I have not done any port mapping here.

Step 2: Now after entering into container’s shell, Install Web Server of your choice, I am using Apache httpd.

Installing Apache httpd

Step 3: Create a Webpage which will verify successful install of apache.

Creating webpage

Here I have created a basic web page. saying “Hello From Docker Container”, also turn on the httpd service so webserver can able to serve traffic.

To start the httpd service — “/sbin/httpd”

starting httpd service inside docker

Step 4: Download Ngrok, and install

To download —

“yum install wget unzip -y (To install wget and unzip agent for download and unzipping)

Install wget and unzip

“wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip

Downloading ngrok

Now unzip it using — “unzip ngrok-stable-linux-amd64.zip”

unzipping ngrok

now we got a executable after unzipping, you can copy it in “/bin” folder to access from anywhere.

copying ngrok to /bin

now create a tunnel, using the following command to expose the web traffic.

“ngrok http 80”

creating http tunnel

Now you can see the ngrok dashboard and the public http or https url on the dashboard. Copy these url and paste it in your browser.

ngrok dashboard

Successful, Now we are able to access content inside our container publicly without any external IP via ngrok tunnel.

Responses to tunnel

You can also see the number of requests coming to your machine through this dashboard.

Thanks for reading this blog, Hope you liked it.

--

--

Abhishek Sahu

Hey Readers, I am tech enthusiast and an Computer Science Student. Here I am sharing various industry use cases and its solution.