Cloudflare basics: domains, IPs, Pages, Workers and Tunnel
One path diagram for Cloudflare: how domains and DNS work, where Pages and Workers fit, how Tunnel avoids inbound ports, and the order to debug a request.
Updated 2026-11-16
Separate the four layers first
Most debugging detours come from mixing layers. Keep these four apart:
- Domain and DNS: the name a visitor types, and the address it resolves to.
- Edge network: Cloudflare receives the request and decides whether to cache, forward, block or reject it.
- Origin or tunnel: which machine, port and process the request reaches.
- Application: whether the process is running, the config is live, and what the logs say.
A 502 can come from a closed port, a wrong tunnel ingress, a crashed app or an Access policy. Find the layer first, then change something.
Domains and DNS
Registrar and nameserver are different jobs
- The registrar owns the name and the renewal.
- DNS hosting decides where the name points.
A common mistake is editing an A record at the registrar while the nameservers already point at Cloudflare. Check the nameservers first:
dig +short NS your-domain.tld
Record types
| Type | Use | Watch out |
|---|---|---|
A |
name → IPv4 address | home IPs change; use DDNS |
AAAA |
name → IPv6 address | do not add it if the host has no IPv6 route |
CNAME |
name → another name | root CNAME support varies |
TXT |
verification, SPF, DKIM | do not pile every verification on one name |
MX |
changing it affects inbound mail |
Proxy status and TTL
Orange cloud means traffic goes through Cloudflare; grey means DNS only. With the proxy on, TTL is managed by Cloudflare, and origin certificates and return-to-origin settings matter too.
Useful default: make the service work in DNS-only mode first, then enable the proxy. That separates “origin unreachable” from “edge configuration wrong”.
DNSSEC
DNSSEC reduces DNS cache poisoning, but it is not a free win. If the DS record and Cloudflare keys drift, the domain can stop resolving. Confirm registrar support and avoid casual nameserver changes after enabling it.
IP addresses and ports
Public IP, NAT and CGNAT
A home connection’s “public IP” is not always a public IPv4 address:
- Real public IPv4: reachable directly.
- Behind NAT: needs port forwarding; the ISP may block 80/443.
- CGNAT: many users share one egress IP; port forwarding usually fails.
A quick signal is the WAN address on the router: 10., 172.16–31. and 192.168. are private ranges. Even a public WAN address can still sit behind carrier NAT.
Prefer a tunnel to port forwarding
Port forwarding exposes a service directly to the internet; scanners find it in minutes. Safer:
- Use Cloudflare Tunnel or a VPN so the connection is established from inside out.
- Put authentication in front, not “a path nobody knows”.
- Make the origin listen on an internal address, not
0.0.0.0.
If forwarding is unavoidable, restrict source addresses, open only the required port, isolate the service and add authentication.
Pages: static sites
Cloudflare Pages fits static HTML/CSS/JS, pre-rendered sites and light Pages Functions.
- Build: connect a Git repo or upload the output; get the build command and output directory right.
- Custom domain: still a DNS operation; certificates are issued by Cloudflare.
- Preview deployments: each branch can get a preview URL; assume previews can be found by search engines.
- Limits: Pages is not a general-purpose server. For long-running processes, database pools or heavy file work, use Workers, a container or your own machine.
Workers: edge functions
Workers fit request handling at the edge: auth, rewrites, A/B, small APIs and scheduled jobs.
- Bindings: KV, D1, R2 and Queues are reached through bindings, not account keys in code.
- Routes: can sit on a custom domain or
workers.dev; match order matters. - Cron: scheduled work needs a declared trigger.
- Logs: use
wrangler tailor console logs; never print tokens or personal data.
Workers have CPU and request limits. Put heavy work in a queue or at the origin.
Tunnel: an inside-out connection
Cloudflare Tunnel works from the inside out: the internal machine connects out to Cloudflare, and public requests come back over that connection. No inbound port on the router.
Typical steps:
- Install
cloudflaredon the target machine. - Create a tunnel and keep its token or credentials file.
- Configure ingress: hostname → local service.
- Point DNS at the tunnel.
- Add an Access application and policy if identity is required.
Debug in order: is the tunnel connected, does ingress match, is the local service listening?
cloudflared tunnel info <tunnel-name>
curl -I http://127.0.0.1:8080
“Tunnel healthy” only means the connection is up. It does not mean the local service is reachable or the Host header matches.
R2, D1 and Queues
- R2: object storage for images, backups and delivery files. Private by default; public access is explicit.
- D1: SQLite-style edge database for small structured data and metadata; not a high-concurrency primary database.
- Queues: async work; move slow operations off the request path and design retries plus a dead-letter path.
Ask: does this data need strong consistency, how often is it read, and can a failure be replayed?
Debugging order
| Symptom | Look at first | Common cause |
|---|---|---|
| Domain does not load | dig, nameservers, records |
nameservers not active, deleted record, DNSSEC mismatch |
| Certificate error | edge certificate, origin certificate | expired origin cert, wrong proxy port |
| 502 / 521 / 522 | origin listening, tunnel state | process down, wrong port, firewall |
| Login page loop | Access app and policy | policy mismatch, missing service token |
| Stale content | cache status, deployed build | cache rule, failed deploy, browser cache |
| Only some users affected | geography, IP, device policy | Access rules, WAF, rate limit |
Common mistakes
- Treating
cf-cache-statusas application logs. It only says whether the edge cached the response. - Blaming the tunnel for every 502. A healthy tunnel with a dead origin still returns 502.
- Running a long-lived service on Pages. Static hosting is not general compute.
- Testing the origin IP while the proxy is on. You are not testing the path users take.
- Treating Access as application authorisation. It protects the entrance, not the app’s own roles.
Next
- Want to size your hardware: run the assessment on the home page.
- Want one front door for several services: read Traefik.
- Want no inbound ports: read cloudflared.
- Want the security baseline first: read network security.
Not sure where to start?
Run the assessment first, or send your setup and goal by email. The reply says whether it fits and what happens next.