# Self-Host Your Apps Behind CGNAT — No Public IP, No Port Forwarding

*Published 2026-11-07 · Self-Hosting, DevOps, Cloudflare, Homelab*

> Host real web apps from a home server, a Raspberry Pi, or an old laptop behind CGNAT (Jio/Airtel) using Dokploy + a Cloudflare Tunnel — no public IP, no port forwarding, free TLS.

Source: https://www.yashthakur.com/blog/self-host-behind-cgnat

---

**The short answer:** you can host real web apps — on a real domain, with free HTTPS — from a machine sitting behind CGNAT (Jio, Airtel, most residential broadband) with **no public IP and no port forwarding**. The trick is that CGNAT only blocks *inbound* connections. A Cloudflare Tunnel runs an agent on your box that dials *outbound* to Cloudflare and keeps the pipe open; public traffic flows back down it. Pair that tunnel with [Dokploy](https://dokploy.com) — a self-hosted, Heroku-style PaaS — and you get a clean deploy workflow on hardware you already own: a home server, a Raspberry Pi, or that old laptop gathering dust in a drawer.

I packaged the whole setup as an open skill — [selfhost-without-public-ip on GitHub](https://github.com/yash-thakur/selfhost-without-public-ip) — after getting tired of re-deriving it every time. This post is the why and the shape of it; the repo is the copy-paste runbook.

## The CGNAT myth, busted

If you've ever tried to self-host from home and hit a wall, it was almost certainly CGNAT (carrier-grade NAT). Your ISP hands you a private address shared across many customers, so there's no public IP pointed at your router and port forwarding does nothing — nobody on the outside can open a connection *to* your box.

Here's the thing everyone misses: **CGNAT only blocks inbound.** Outbound connections work fine — that's how you browse the web. A Cloudflare Tunnel is built entirely on outbound: the `cloudflared` agent on your machine reaches *out* to Cloudflare's edge and holds that connection open. When a visitor hits `app.yourdomain.com`, Cloudflare routes the request back down the existing pipe. The outside world never opens a fresh socket to your box, so CGNAT has nothing to block. This isn't a hack around CGNAT — it's the canonical way to self-host from behind it.

## The pieces

```
browser → https://app.yourdomain.com
   → Cloudflare edge            (TLS terminates here; DDoS protection)
   → Cloudflare Tunnel          (OUTBOUND from your box — beats CGNAT)
   → cloudflared → localhost:80 (Dokploy's Traefik reverse proxy)
   → Traefik routes by Host header → your app's container
```

- **Dokploy** is a self-hosted PaaS with a web UI and a built-in Traefik reverse proxy. You push a Docker image or a repo, it runs it, and it routes by hostname. Think Vercel/Heroku, but on your hardware.
- **Cloudflare Tunnel (`cloudflared`)** is the outbound agent that makes your box reachable without a public IP. One tunnel serves any number of apps and domains — adding an app is one ingress line plus one DNS record, never a new tunnel.

## You don't need a server — a Raspberry Pi or old PC is perfect

This is the part I want to push hardest, because it's where most people over-spend. **You do not need to rent a VPS or buy a server.** The whole architecture is designed so your home machine *is* the server, and "home machine" can be deliberately humble:

- **A Raspberry Pi 4 or 5** (4–8GB) sips power — a few watts, cheap to leave on 24/7 — and comfortably runs Dokploy plus a couple of small apps. Put the OS and Docker data on an SSD over USB rather than a tired SD card and it'll be reliable for years.
- **An old laptop** is arguably the *best* option. It has a built-in battery, which is a free UPS — a power blip won't take your sites down. It has a keyboard and screen for recovery, and an old i5 with 8GB wipes the floor with any entry VPS. The one thing to fix: stop it suspending when you close the lid (set `HandleLidSwitch=ignore` in `/etc/systemd/logind.conf`), then shut the lid and slide it onto a shelf.
- **Any idle mini-PC or desktop** works the same way. If it can run Ubuntu and Docker, it can host.

The economics are hard to argue with: hardware you already own, your existing home internet, and Cloudflare's free tier. Your only real cost is a domain name. An old laptop that was going to the e-waste pile becomes a legitimate always-on app server.

A couple of honest constraints on small boxes. On 8GB, **add swap** — Docker and Next.js builds spike memory and will get OOM-killed without it:

```BASH
sudo fallocate -l 4G /swapfile && sudo chmod 600 /swapfile
sudo mkswap /swapfile && sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
echo 'vm.swappiness=10' | sudo tee /etc/sysctl.d/99-swappiness.conf && sudo sysctl --system
```

And run one or two apps at a time, not a dozen. Dokploy itself idles around 1–1.5GB, leaving most of an 8GB box for your workloads. If a build is too heavy for the Pi, build the image on your dev machine and deploy it prebuilt.

## The deploy loop, once it's up

After the one-time install (Dokploy via its installer, `cloudflared` authenticated to your domain, the tunnel running as a service), adding an app is genuinely three small steps:

```BASH
# 1. Add one ingress block in /etc/cloudflared/config.yml, above the 404 catch-all:
#      - hostname: newapp.yourdomain.com
#        service: http://localhost:80
sudo systemctl restart cloudflared

# 2. Create the DNS record (one command):
cloudflared tunnel route dns dokploy newapp.yourdomain.com

# 3. In Dokploy: app → Domains → add the host, set the container port, HTTPS off
#    (Cloudflare already does TLS — a per-app cert would be redundant and fail)
```

That's it. The app is live on a real domain with HTTPS, served from a Raspberry Pi behind your home router.

## Where this fits — and where it doesn't

This is a brilliant fit for the stateless request/response web: marketing sites, dashboards, APIs, side projects, internal tools, a staging environment for client work. It is *not* the right home for things that need a persistent logged-in session or a real display — WhatsApp-automation workers, headless-browser jobs, Electron desktop apps. Keep those local; host the web half.

If you're deciding *what* to put on it, the trade-offs are the same ones I covered in the vibe-coding series — [how to choose a backend](/blog/how-to-choose-a-backend) for the runtime/database fit, [architecture for your user count](/blog/architecture-by-user-scale) for whether a single box is enough (for most side projects and small apps, it comfortably is), and [security and networking precautions](/blog/security-networking-precautions) because exposing anything to the internet — even through a tunnel — means getting auth, secrets, and the firewall right.

## Use agents and skills deliberately

The setup has a handful of sharp edges — the installer needing a real root shell, Cloudflare's SSL mode causing redirect loops on *Flexible*, the 1033/502 errors when an ingress hostname or Dokploy domain is misconfigured. That's exactly why I wrote it up as a reusable skill rather than a one-off: the [selfhost-without-public-ip](https://github.com/yash-thakur/selfhost-without-public-ip) repo carries the full runbook, an `nginxdemos/hello` smoke test to prove the chain end to end, and a troubleshooting table for every failure mode I hit. Point your coding agent at it and it can drive the whole install, or you can follow it by hand.

Self-hosting used to mean either a VPS bill or a fight with your router that CGNAT quietly made unwinnable. It doesn't anymore. An old laptop, a free Cloudflare account, and an outbound tunnel are all it takes to turn idle hardware into a real, public, HTTPS-served app platform — and to stop paying rent on someone else's computer for projects that fit comfortably on your own.
