Cloudflare Tunnel. How to put my local website online

Esteban Suárez

Cloudflare is one of the largest networks in the world. Today, the websites and applications of businesses, nonprofits, bloggers, and anyone with an online presence are faster and more secure with Cloudflare.

Having an online site normally requires a series of resources such as:

  1. Domain Name (Required)
  2. Hosting Server
  3. DDOS mitigation services or brute force attacks
  4. SSL certificates

Just to count the most common for an average user. But what would happen if it becomes too complicated for us to hire online hosting? Or if we simply want to put online one of the sites or services that we have running on our local server or our home computer?

If you have these doubts, do not stop reading this article where I am going to explain what Cloudflare is, what Cloudflare Tunnel is and how you can set up your local site in just a few minutes and without spending a single penny.

What is Cloudflare?

According to the official site: Cloudflare is one of the largest networks in the world. Today, the websites and applications of businesses, nonprofits, bloggers, and anyone with an online presence are faster and more secure with Cloudflare.

how does it work?

In the early days of the Internet, when you wanted to load a website, your request went from your computer to a server, which then returned the web page you requested. Connection between the computer and the server

If too many requests came in at once, that server could become overloaded, crash, and stop responding to requests from anyone trying to access the resources it hosted.

This problem made it difficult for website owners to offer fast, secure and reliable content. Thus, Cloudflare was born, with the aim of overcoming these difficulties and offering users the necessary resources to allow their sites, applications and blogs to be safe and effective. All this is possible thanks to the use of a powerful perimeter network that offers content and other services as close as possible to users, so that you get the information as quickly as possible.

How can this benefit you?

By using Cloudflared you benefit from protection against denial of service attacks (DDOS), an SSL certificate valid for an unlimited time, faster loading speeds for clients. Something very important when providing services on the Internet and other associated services that have been increasing over time.

What is Cloudflared Tunnel?

Cloudflare Tunnel is tunneling software that allows you to quickly secure and encrypt application traffic to any type of infrastructure, so you can hide the IP addresses of your web servers, block direct attacks, and bring great applications back to life.

In essence it is a tunnel that can connect any service you have running locally to a domain you have on the internet. Whether you’re behind a firewall or not. Creating my tunnel step by step

To start this tutorial, the first thing we need to do is create a Cloudflare account. To do this, we go to the [Cloudflare] website (https://cloudflare.com) using the browser of our choice.

cloudflare home page

Once we’re on the Cloudflare website, if this is the first time you’ve heard of Cloudflare and you don’t have an account yet, go to Sign Up and create your account with the information requested.

Once you have your account created and verified, you will log in to your cloudflare account with your username and password. It is always recommended that in Settings, Security you add a double authentication factor 2FA.

In the Dashboard or main Panel that you will have when you open your account you will see a button that says Add a site.

cloudflare registrar dominio

Once this step is done, you must write the name of a domain in your name and in which you have access to the DNS records to modify them.

cloudflare add domain

To verify that you are the owner of the domain, you must add the records that Cloudflared will provide you with the registrar of the domain that you are using. Then you click verify.

Note: If you don’t have a domain and want to buy one you can do it through Cloudflare’s domain registrar or you can go to Namecheap.com although there are others on the internet and you can choose the one you like as long as you have control of the DNS records.

Once these steps have been completed and with your domain pointing to cloudflare, we proceed to create the tunnel to publish our local website on the Internet. First steps to create our tunnel

To create our tunnel we must meet several requirements.

  1. Have a Computer
  2. Internet access
  3. Know what Platform we are working on (Windows, Linux, Mac)
  4. Download the cloudflare software.

Fulfilled the requirements 1, 2, 3 we go directly to number 4. Cloudflare Download

We go to the Cloudflare Download Center where we are going to download the software for the platform we have .

Once we have downloaded the file that we are going to use, we proceed to install it. We configure the tunnel

To configure the Tunnel, the first thing we must do is log in, keep in mind that this is a process that we are going to carry out from a terminal in which we write the following command.

cloudflared tunnel login

Then a link will be displayed on the screen which you must open in the browser with your cloudflared account open to choose which domain is going to have the tunnel and generate the access certificate (cert.pem) for it .

The output in the terminal should be something like this:

A browser window should have opened at the following URL:

https://www.cloudflare.com/a/warp?callback=<some token>

If the browser failed to open, open it yourself and visit the URL above.

To create a new tunnel, use the following command:

cloudflared tunnel create <TUNNEL_NAME>

Where NAME_DEL_TUNEL is the name of the subdomain that you will put on your website.

Example 1:

cloudflare tunnel create www

If the domain registered in your Cloudflare account is example.com, the tunnel created above will redirect your service to www.example.com

Example 2:

cloudflare tunnel create test

It will redirect your local service to test.example.com

If you want to verify that the tunnel was created correctly or the number of tunnels you have created, you can use:

cloudflared tunnel list

If you want to delete a tunnel that you have created by mistake or that you will not use again, use the following command:

cloudflared tunnel delete <TUNNEL_NAME>
If you want to run your tunnel with a service that is running on port 80 of your computer, as an example you could use the following command
cloudflared --hostname <TUNEL_NAME.example.com> --url localhost:80

In this way you could make that project you have been working on for a while accessible from the internet.