Self-hosting your own services such as websites, applications, and file servers has become increasingly popular due to the rise of cloud computing. However, one major challenge with self-hosting is making these services accessible from the Internet.
In the last blog, I mentioned a solution using Cloudflare API for DDNS which works great if you have a Dynamic IP address.
However, if you don’t then don’t worry because this is where Cloudflare Tunnels comes into play, offering a simple and secure way to expose your services to the world.
Cloudflare Tunnels is a service offered by Cloudflare, a popular Content Delivery Network (CDN) and security provider. It enables you to make your self-hosted services accessible from the Internet without the need for complicated port forwarding or firewall configurations.
Cloudflare Tunnel can connect HTTP web servers, SSH servers, remote desktops, and other protocols safely to Cloudflare.
Cloudflare Tunnels utilizes its Edge infrastructure to create a secure and encrypted connection between your self-hosted services and the Internet.
When someone tries to access your service, the request is intercepted by the Cloudflare Edge Servers, which then forwards the request to your service and returns the response back to the user.
This entire process happens in real-time, ensuring fast and secure access to your services.
If you don’t already have a Cloudflare account, you can sign up for one here ↗️.
Once you’ve logged into your Cloudflare account, click on the “Add a Website” button, enter your website’s URL, and follow the steps to add your website to Cloudflare.
Cloudflared is the CLI tool that enables you to create tunnels to your self-hosted services. You can install it on your device by following the instructions on developer docs section ↗️.
Once you have installed cloudflared, you will need to authenticate with Cloudflare. To do this, run the following command:
This will prompt you to enter your Cloudflare account email and API key. Once you have entered this information, you will be authenticated with Cloudflare and ready to start setting up tunnels.
To create a new tunnel, you will use the following command:
<tunnel-name> with the name of the service you want to expose. This will create a new tunnel and display a unique tunnel ID.
Confirm that the tunnel has been successfully created by running:
Now that you’ve created your tunnel, you need to configure it to point to the service you want to expose. To do this, you’ll need to create a configuration file.
Create a new file in a text editor and paste the following configuration:
<your-tunnel-id> with the ID of your tunnel (which you obtained in step above when we created a tunnel).
<subdomain.hostname.com> with the hostname you want to use for your service (this will be the URL that people use to access it). Replace
<port> with the port number of the service you want to expose (for example, 80 for a web server).
Save this file as
config.yaml in a location of your choice.
Next we want to assign a CNAME record that points traffic to your tunnel subdomain. From the above example it will be whatever you are replacing
<your-tunnel-id> with the ID of your tunnel and
subdomain with the subdomain that you added in the config file.
Now that you’ve configured your tunnel, you can start it by running the following command:
<tunnel-name> with the name you chose for your tunnel in create tunnel section and replace
/path/to/your/config.yaml with the path where you stored the
Now that your tunnel is running, you should be able to access your local service from the internet by visiting the hostname you specified in the configuration file.
Try accessing it from a different network or using a VPN to simulate an external connection.
You can manually go ahead and create a service file for running cloudflared as a service on your system and this guide will help you with that.
However, cloudflared already provides a quick way to set it up with a single command.
After the service is installed, you can start it with this command:
And optionally view the status of the service with
Additionally, I would highly recommend to enable this service so anytime you logout or reboot the system, cloudflared service automatically starts again.
Cloudflare Tunnels is a powerful tool for exposing your self-hosted services to the internet. With a simple and secure setup process, you can quickly and easily connect to your services from anywhere in the world.
Whether you are exposing a single service or multiple services, Cloudflare Tunnels makes it easy to connect to your services and keep them accessible to the world.