Setting up a Cloudflare Tunnel on your Linux
Before you can set up a Cloudflare Tunnel, you need to set up a free Cloudflare account at cloudflare.com
You also need to add the domain name you want to use to your Cloudflare, simply put, your domain name is your web address (e.g. yoursite.com)
If you don’t have one already, you can also register one with Cloudflare, this is the easiest way.
If you want to register elsewhere you’ll need to add it to Cloudflare and follow their instructions for nameserver setup.
Once you have the account and domain name set up on Cloudflare, we can begin.
Open your terminal (Konsole) and use the following command to install CloudFlared:
wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb && dpkg -i cloudflared-linux-amd64.deb
Next, link to Cloudflare:
cloudflared login
This should open your web browser with a login page for Cloudflare to authorise your Tunnel, once you’ve logged in select your domain name and click Authorize
Now create your tunnel:
cloudflared tunnel create <YourTunnelName>
Replace “<YourTunnelName>” with whatever name you want to call your Tunnel, it’s best to use a memorable word.
The output it gives you is important, make a note of the Tunnel’s UUID and the path to the credentials file
Now, we need to create your configuration file
First use this to find out your Linux computers IP address:
hostname -I
Make note of the result, you need this for the configuration file. Next, make the configuration file using this:
sudo nano ~/.cloudflared/config.yml
It will open the editor and now you need to copy and paste the code below into it:
tunnel: <TunnelUUID>
credentials-file: /root/.cloudflared/<TuinnelUUID>.json
ingress:
- hostname: yoursite.com
service: http://192.168.1.1
- service: http_status:404
Replace the following:
<tunnelUUID> with your Tunnel UUID you made note of earlier
yoursite.com with the domain name you added to Cloudflare
192.168.1.1 with your Linux computers IP address
Before we save and close the file, double check that the “credentials-file” matches the credentials file path we made note of earlier, otherwise change it to the correct path.
If it’s all OK, you can save and exit using CTRL + X and then when it asks Save Modified Buffer?, type y and click Enter.
Now, use the following to set it up at Cloudflare:
cloudflared tunnel route dns <TunnelName> <hostname>
Replace <TunnelName> with the tunnel name you chose earlier and <hostname> with your domain name (we set in your configuration file earlier)
All that’s left to do now is run and test your tunnel, we can start running the tunnel using this:
cloudflared tunnel run <UUID or NAME>
Replace <UUID or Name> with your tunnel UUID you made note of or the name you chose for your tunnel
Now you can test your tunnel using this:
cloudflared tunnel info <UUID or NAME>
If it’s working, you should be able to access your Linux computer (web server) from the internet by visiting your domain name (yoursite.com) from any web browser.
If you’re following our guides, you should see the Apache default page:
If you want to find out how to change this into your own website, read our article: Your First Website