Do you want to access your localhost over the internet (without static IP, without a router, without port forwarding) using the HTTPS protocol, remotely access your PC via SSH, or have you set up an FTP server on your system and want to access it for downloading and uploading files from anywhere?
This can all be achieved at once without needing static IP, router, or port forwarding on Linux, Windows, macOS, or Raspberry Pi by simply following the ten simple steps mentioned in this article.
Pre-requisite
The following are a few requirements that must be fulfilled in order for everything to work properly:
- System with active access to the internet.
- A running web server, SSH server, or FTP server on their default port.
- Cloudflare account with one purchased domain name that has subdomain access.
Access Localhost With a Domain Name Using Cloudflare Tunnels
To demonstrate how to reverse proxy with a dynamic IP using Cloudflare, Iβll use my Cloudflare account with my purchased domain name that Iβve already added and configured with nameserver, accessing my PC that has a Nginx server running at port 80 via my domain name.
So, letβs begin.
1. First, Iβll show you that the Nginx server is already running on my local PC on the default port 80.
Now, Iβll show you how to access the above localhost page over the internet with a domain name using Cloudflare.
2. Login to your Cloudflare account, and you will then be redirected to the following page, where you can see I have one domain name added to my account. Therefore, you must also have at least one. Now, in the sidebar, click on the βZero Trustβ option.
3. Now, you will be redirected to the following Zero Trust dashboard: Here, you must first click on the down arrow key next to βNetworksβ and then click on the βTunnelsβ option.
4. On the Tunnel page, click on the βAdd a tunnelβ button.
5. Select βCloudflaredβ as the connector to link your resources (e.g., web server, SSH server, FTP server, etc.) to the Cloudflare global network, then click on the βNextβ button.
6. Name your tunnel, which will help you identify which system is linked to it in the future, and then click on the βSave Tunnelβ button.
7. Choose the local system environment for the connector. For example, if youβre using an Ubuntu system operating on a 64-bit architecture, opt for βDebianβ as the βoperating systemβ and β64-bitβ as the βarchitectureβ, and then proceed to click and copy the provided command.
8. Open your terminal, paste, and execute the previously copied command to install and configure the Cloudflare service.
9. Once the installation is complete, return to your browser, scroll down, and click on the βNextβ button.
10. Itβs time to add the public hostname (the purchased domain in your Cloudflare account) to your tunnel and link the hostname to the Cloudflared service (installed in your system in step eight). For example, for the hostname subdomain, Iβll name it βlinuxtldrβ, select the domain in the βDomainβ dropdown, and leave the βPathβ field empty.
Then, under service, as I am running an Nginx server at port 80 on my system, I will select βHTTPβ for βTypeβ, set the βURLβ as βlocalhostβ, and then click on the βSave Tunnelβ button.
If, while adding the hostname, you encounter the following error:
Then make sure that the specified subdomain is neither already created nor reserved by any other record in the domainβs DNS records.
11. Once the hostname is successfully created, you will be redirected back to the βTunnelsβ page, where you can view the status of the tunnel.
12. Once the tunnel status turns βHEALTHYβ, open your browser and visit the domain you used as a hostname for the tunnel.
Tada!! You have successfully set up a Cloudflare tunnel on your local PC and can now access the web server over the internet via a domain name.
If youβre interested in learning more, do let me know in the comment section; thereβs a lot more you can do with Cloudflare Tunnel.
Till then, peace!
Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.