Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Cloudflare Tunnel Setup for Home Server

· 4 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through setting up a Cloudflare Tunnel to securely expose a home server (like a NAS, Plex, or a web app) to the internet without opening ports on your router or exposing your home IP address. You'll need a domain name managed by Cloudflare and a computer on your home network to run the tunnel daemon. By the end, you'll have a public URL (e.g., yourname.example.com) that routes traffic through Cloudflare's edge network to your server.

What You'll Need

  • A domain name using Cloudflare's nameservers (free plan works).
  • A computer on your home network that stays on (a Raspberry Pi, old PC, or the server itself).
  • Administrative access to that computer (terminal or SSH).
  • The local IP and port of the service you want to expose (e.g., 192.168.1.50:8080).
  • Cloudflare account with the domain added.

Step-by-Step

  1. Install cloudflared – On your home computer, install the Cloudflare daemon. For Linux (Debian/Ubuntu), use sudo dpkg -i cloudflared-linux-amd64.deb after downloading from the official Cloudflare repo. For macOS, use brew install cloudflared. For Windows, download the exe and place it in a folder.
  2. Log in to Cloudflare – Run cloudflared tunnel login. This opens a browser to authorize your Cloudflare account. Select the domain you want to use. This creates a certificate file (~/.cloudflared/cert.pem).
  3. Create a tunnel – Run cloudflared tunnel create home-server. Replace home-server with any name. This creates a tunnel ID and a credentials file (JSON) in ~/.cloudflared/.
  4. Create a configuration file – In ~/.cloudflared/config.yml, add:
    tunnel: home-server
    credentials-file: /home/youruser/.cloudflared/home-server.json
    
    ingress:
      - hostname: yourname.example.com
        service: http://192.168.1.50:8080
      - service: http_status:404
    Adjust the hostname and service URL to match your setup.
  5. Route DNS – Run cloudflared tunnel route dns home-server yourname.example.com. This creates a CNAME record pointing to your tunnel.
  6. Run the tunnel – Start it with cloudflared tunnel run home-server. Test by visiting https://yourname.example.com from any device.
  7. Run as a service – To keep it running after reboot, install it as a systemd service (Linux): sudo cloudflared service install. For macOS, use brew services start cloudflared. For Windows, create a scheduled task or use NSSM.

Common Mistakes

  • Wrong service URL – Using http://localhost:8080 when the tunnel runs on a different machine than the server. Use the server's LAN IP.
  • Forgetting the catch-all rule – The last ingress rule must be service: http_status:404, otherwise the tunnel fails to start.
  • Port already in use – If your server uses port 80 or 443, make sure no other process is bound to them locally.
  • DNS propagation delay – Even with Cloudflare, DNS changes can take a few minutes. Be patient.
  • Using HTTP instead of HTTPS – Cloudflare provides HTTPS automatically, but if your service is HTTP-only, the tunnel handles it. Don't set service: https:// unless your service has a valid cert.

Tips

  • Use a subdomain like nas.example.com rather than the root domain to avoid conflicts with other services.
  • Secure your service with Cloudflare Access (Zero Trust) to add an extra login layer.
  • If you have multiple services, add multiple ingress rules with different hostnames.
  • Keep the tunnel software updated to get security patches and new features.
  • For high traffic, consider using Cloudflare's load balancer or multiple replicas of the tunnel on different machines.

Troubleshooting

Tunnel won't start – Check the config file for syntax errors. Run cloudflared tunnel ingress validate to test the rules.

Site returns 502 or 530 – The tunnel is up but can't reach your service. Verify the service is running and the IP:port is correct. Test locally with curl http://192.168.1.50:8080.

DNS not resolving – Run cloudflared tunnel route dns again. Check the Cloudflare dashboard for the CNAME record.

Certificate expired – If you get an error about cert.pem, run cloudflared tunnel login again.

Service not accessible from outside – Ensure your router firewall isn't blocking outbound connections from the tunnel machine (cloudflared makes outbound connections only, so inbound ports are not needed).

Frequently Asked Questions

Do I need to open ports on my router?

No. Cloudflare Tunnel makes outbound connections from your home network to Cloudflare, so no inbound ports are required.

Can I expose multiple services with one tunnel?

Yes, add multiple ingress rules with different hostnames in the config file.

Is Cloudflare Tunnel free?

Yes, the free plan includes unlimited tunnels and 1GB of traffic per month per zone.

What if my home IP changes?

It doesn't matter. The tunnel connection is initiated from your side, so IP changes don't affect the public URL.

Can I use Cloudflare Tunnel with a non-HTTP service like SSH?

Yes, you can set the service to ssh://localhost:22 and access it via ssh -p 22 user@yourname.example.com (after configuring the tunnel for TCP).

How do I stop the tunnel?

If running as a service, use sudo systemctl stop cloudflared (Linux) or brew services stop cloudflared (macOS). If running manually, press Ctrl+C.