Cloudflare Installation

 Well, now the million-dollar question, how can I make my website accessible to everyone? My ISP doesn't provide a public IPv4, so I thought about using a DDNS service like No-IP or the one included in Google Domains . However, I encountered another problem; my ISP uses double NAT, meaning my IPv4 could only be accessible to other users on my ISP. I realized I had a public IPv6 (although I believe it's also dynamic), so I added all my domains in AAAA records pointing to my IPv6 in the DNS. It worked for a moment, this way I didn't have to open ports on my router because that IP was unique to my PC. But there was a serious issue; my site was inaccessible to any network that didn't have IPv6 enabled (for example, my school's network).

My sites remained like this until one day I discovered a video by Network Chuck talking about Cloudflare Tunnels. I followed the instructions in his video, with a few small changes :3

I wanted to create the tunnel from the terminal and not in the panel, so I followed the instructions in the docs Create a locally-managed tunnel (CLI) · Cloudflare Zero Trust docsfor creating a locally-managed tunnel (CLI).

Afterwards, I found it very complicated to write the entire command to start my tunnel, so I created this script to execute it with 'mytunnel' (remember to make it executable).

#!/bin/bash
# Save this file in /usr/local/bin
sudo cloudflared tunnel run mytunnel
view raw mytunnel hosted with ❤ by GitHub

It was also challenging to write the entire command to add my subdomain to the DNS, so I made this script.

#!/bin/bash
# Save this file in /usr/local/bin
read -p "Ingresa el subdominio: " subdomain
if [ -z "$subdomain" ]; then
echo "Error: Debes ingresar un subdominio."
exit 1
fi
echo "$subdomain.example.com"
sudo cloudflared tunnel route dns mytunnel $subdomain
view raw mytunneldns hosted with ❤ by GitHub

Finally, I didn't want to have a terminal where the tunnel was always running, especially because I had to disconnect the SSH. So, I turned it into a service to start at system boot (remember to enable your service).

# Save this file in /etc/systemd/system
[Unit]
Description=Start Cloudflare tunnel on boot
[Service]
Type=simple
ExecStart=/usr/local/bin/mytunnel
[Install]
WantedBy=default.target

No comments:

Post a Comment

Hay alguien detrás de la puerta

 No sé por qué, otra vez, me estoy sintiendo así. Como un vacío que recorre mi cuerpo, del que no puedo escapar. En cualquier momento va ...