How to Connect Namecheap with Cloudflare Tunnel

How to Connect Namecheap with Cloudflare Tunnel

Introduction

If you're looking to host a web service and make it accessible via a domain registered on Namecheap while keeping your connection secure, Cloudflare Tunnel is a great solution. This guide will walk you through setting up a Cloudflare Tunnel on both Termux (Android) and a Laptop (Linux/Mac/Windows) and integrating it with Namecheap.


What is Cloudflare Tunnel?

Cloudflare Tunnel provides a secure way to expose local applications running on localhost to the internet, without opening ports on your router. It works as a reverse proxy, routing your traffic through Cloudflare’s network.

Prerequisites

  • A Namecheap domain.

  • A Cloudflare account (Free).

  • A laptop (Linux/Mac/Windows) or an Android device with Termux.
  • Installed Cloudflared on your system.

Step 1: Install Cloudflared

On Termux (Android)

pkg update && pkg upgrade -y
pkg install wget
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm -O cloudflared
chmod +x cloudflared
mv cloudflared $PREFIX/bin/

Verify installation:

cloudflared --version

On Laptop (Linux/macOS)

wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -O cloudflared
chmod +x cloudflared
sudo mv cloudflared /usr/local/bin/

For Windows, download Cloudflared from Cloudflare’s official site.

Verify installation:

cloudflared --version


Step 2: Authenticate Cloudflare

Run the following command to log in to your Cloudflare account:

cloudflared tunnel login

This will open a browser link; log in to Cloudflare and select your domain.


Step 3: Create a Cloudflare Tunnel

Create a new Cloudflare Tunnel:

cloudflared tunnel create my-tunnel

This will generate a UUID (unique tunnel ID). Example output:

Tunnel credentials written to /home/user/.cloudflared/UUID.json


Step 4: Configure Cloudflare Tunnel

Create a configuration file:

mkdir -p ~/.cloudflared
nano ~/.cloudflared/config.yml

Add the following configuration (replace UUID with your actual Tunnel ID):


tunnel: UUID
credentials-file: /home/user/.cloudflared/UUID.json

ingress:
  - hostname: yourdomain.com
    service: http://localhost:8080
  - hostname: www.yourdomain.com
    service: http://localhost:8080
  - service: http_status:404


Save and exit the file.


Step 5: Add DNS Records in Cloudflare

Since you have your domain on Namecheap, but want to use Cloudflare’s DNS, follow these steps:

  1. Go to Cloudflare Dashboard.
  2. Navigate to DNS Settings.
  3. Click Add Record and select CNAME.
  4. Add the following records:
    • Name: yourdomain.com

    • Target: UUID.cfargotunnel.com (Replace UUID with your actual tunnel ID)

    • Proxy Status: Proxied (Orange Cloud)
  5. Repeat the process for www.yourdomain.com.


Step 6: Update Namecheap DNS Settings

  1. Log in to Namecheap.

  2. Navigate to Domain List and select your domain.
  3. Click Manage → Scroll to Nameservers.
  4. Choose Custom DNS and enter the Cloudflare Nameservers (found in Cloudflare Dashboard under DNS Settings).
  5. Save the changes.

Step 7: Start Cloudflare Tunnel

On Termux

cloudflared tunnel run my-tunnel

To run it in the background:

nohup cloudflared tunnel run my-tunnel &

On Laptop

cloudflared tunnel run UUID

To run as a background service:

cloudflared service install
systemctl start cloudflared
systemctl enable cloudflared


Step 8: Verify the Connection

Check the status of your Cloudflare Tunnel:

cloudflared tunnel list

If everything is correct, your domain should now be accessible via Cloudflare!


Conclusion

By following this guide, you’ve successfully connected your Namecheap domain with Cloudflare Tunnel using Termux or a Laptop. Your website is now securely accessible without exposing your local machine’s ports to the public.

If you face any issues, feel free to check Cloudflare’s logs with:

cloudflared tunnel log

Enjoy your secure and seamless Cloudflare Tunnel setup! 🚀


1 Comments

imvickykumar999

Thanks to this blog which helped in hosting locally from Mobile. https://imvickykumar999.online

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading...