Cloudflare 01 ☁️ Introduction, DNS & The Edge Network — Setting up Cloudflare DNS, the orange-cloud proxy, Anycast routing, and SSL/TLS modes
Cloudflare operates as a reverse proxy that sits between your web server (the origin) and the global internet. Unlike a traditional DNS provider that simply resolves domain names to IP addresses, Cloudflare acts as an active intermediary. When you point your nameservers to Cloudflare, they intercept every request directed to your domain, process it at the nearest edge server, and only forward the request to your origin if necessary. This architecture allows Cloudflare to inspect traffic, cache assets, block threats, and terminate SSL connections before they ever reach your infrastructure.
This chapter explores the fundamental mechanisms of the Cloudflare network, beginning with how DNS is handled via Anycast routing. We will dissect the “orange cloud” proxy mechanism, which distinguishes Cloudflare from standard DNS providers, and examine the different SSL/TLS encryption modes that dictate how traffic is secured between the user, the edge, and your origin server.
Key point: The “Orange Cloud” proxy icon represents the transition from simple DNS resolution to a full reverse-proxy architecture, where Cloudflare terminates the user’s connection at the edge, inspects the traffic, and enforces security policies before forwarding requests to your origin server.
Why X exists
The latency problem. Traditional internet routing is geographically inefficient. A user in Tokyo accessing a server in New York experiences significant latency due to the number of network hops. Cloudflare’s Anycast network exists to reduce this by routing users to the nearest data center (Edge Node), caching content closer to the consumer.
The DDoS vulnerability. Small and medium-sized servers cannot handle massive volumetric traffic. If an attacker knows your server’s true IP address, they can overwhelm your network interface directly. Cloudflare exists to hide the origin IP behind a global, distributed network capable of absorbing terabytes of malicious traffic.
The SSL/TLS complexity. Implementing and maintaining SSL certificates on every origin server can be a logistical burden. Cloudflare simplifies this by providing “Edge Certificates,” allowing you to encrypt traffic to the browser while using more flexible or simplified encryption settings on your origin.
The caching inefficiency. Requesting raw data from a database-backed server for every page load is expensive and slow. Cloudflare provides a caching layer that stores static assets (CSS, JS, Images) at the edge, reducing the load on your origin by orders of magnitude.
The trade-off. The primary trade-off is control versus abstraction. By routing traffic through Cloudflare, you lose direct visibility into the user’s source IP unless you configure your server to trust Cloudflare’s headers (like CF-Connecting-IP). Furthermore, you introduce a single point of failure—if Cloudflare’s edge experiences an outage, your site goes down.
a. Anycast DNS and The Edge Network
Standard DNS (Unicast) resolves a domain to a specific IP address tied to a specific physical location. If that server goes down, the DNS is useless. Cloudflare uses Anycast routing. In an Anycast network, the same IP address (Cloudflare’s nameservers) is announced from hundreds of data centers simultaneously. When a user performs a DNS query, the BGP (Border Gateway Protocol) routing naturally directs them to the closest available data center.
This mechanism is not just for DNS. When you enable the “Orange Cloud” (proxying), your domain resolves to Cloudflare’s Anycast IP addresses, not your server’s IP. This means the first handshake occurs between the user and the nearest Cloudflare Edge Node. The user is never directly connected to your origin server, providing an immediate layer of obfuscation.
User ──► [ Nearest Cloudflare Edge (Anycast) ] ──► [ Your Origin ]
This ensures that even if you have a single origin server, your site feels globally distributed. The edge node handles the initial request, checks the cache, runs security filters, and handles TLS negotiation, only passing the request to the origin if no cached content is available.
b. The Orange-Cloud Proxy
The “Orange Cloud” is the UI representation of the Reverse Proxy. When a DNS record in Cloudflare is “proxied” (Orange), Cloudflare acts as the server for that record. When it is “DNS Only” (Grey), Cloudflare acts merely as a DNS provider, passing the query to your IP and staying out of the traffic path.
When proxied, Cloudflare performs SSL termination. The browser establishes an HTTPS connection to Cloudflare’s edge. Cloudflare then establishes a second connection from its edge to your origin. This allows Cloudflare to inspect the payload for SQL injection, XSS attacks, and bot behavior.
DNS Only (Grey) : Browser ──► [ DNS lookup ] ──► Your Origin IP
Proxied (Orange) : Browser ──► [ Cloudflare Proxy ] ──► Your Origin IP
Because Cloudflare is the proxy, it rewrites the headers of the incoming request. Your server will see Cloudflare’s IP addresses in the logs unless you configure your web server (Nginx/Apache) to read the X-Forwarded-For or CF-Connecting-IP headers to identify the actual visitor.
c. SSL/TLS Encryption Modes
SSL modes dictate how the traffic flows between the user, Cloudflare, and your origin server. It is a common point of misconfiguration.
- Flexible: Cloudflare handles HTTPS for the user, but the connection from Cloudflare to your origin is plain HTTP (port 80). Recommendation: Avoid this. It is not end-to-end encrypted.
- Full: Cloudflare encrypts the connection to the user, and connects to the origin via HTTPS (port 443). The origin can use a self-signed certificate, which Cloudflare accepts without validation.
- Full (Strict): The gold standard. Cloudflare encrypts the connection to the user, and requires a valid, trusted SSL certificate on your origin server. This ensures the connection is encrypted and verified at every hop.
[ Browser ] ──HTTPS──> [ Cloudflare Edge ] ──HTTPS (Strict)──> [ Origin ]
You should almost always use “Full (Strict)” combined with an Origin CA certificate (a free, long-lived certificate provided by Cloudflare specifically for this purpose).
Complete Example Session
// ============================================
// PART 1: DNS RECORD SETUP
// ============================================
// Add a record in Cloudflare DNS dashboard
// Type: A
// Name: @ (Root)
// IPv4 address: 192.0.2.1 (Your Origin IP)
// Proxy status: Proxied (Orange)
// ============================================
// PART 2: SSL/TLS SETTINGS (API CONFIG)
// ============================================
// Set mode to Full (Strict) to ensure end-to-end security
// This requires a valid cert on the origin
// ============================================
// PART 3: NGINX ORIGIN CONFIG (TRUSTING CLOUDFLARE)
// ============================================
// Allow Cloudflare IPs only to prevent bypass
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
real_ip_header CF-Connecting-IP;
// ============================================
// PART 4: HSTS CONFIGURATION
// ============================================
// Enforce HTTPS at the edge
// Crypto > SSL/TLS > Edge Certificates > Always Use HTTPS
// ============================================
// PART 5: ORIGIN CA CERTIFICATE
// ============================================
// Generate an Origin CA Cert in Cloudflare
// Install on your Origin server (e.g., Nginx)
ssl_certificate /etc/nginx/certs/origin.crt;
ssl_certificate_key /etc/nginx/certs/origin.key;
// ============================================
// PART 6: BYPASSING PROXY (GREY CLOUD)
// ============================================
// Switch proxy status to "DNS Only"
// Use this for SSH/SFTP or direct origin access
// ============================================
// PART 7: CACHE PURGE
// ============================================
// Use API to purge cache after deployment
curl -X POST "https://api.cloudflare.com/..." \
-H "X-Auth-Email: ..." \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'
// ============================================
// PART 8: FIREWALL RULES
// ============================================
// Block specific countries or botnets at the edge
// Before they hit your origin server
// ============================================
// PART 9: DEVELOPMENT MODE
// ============================================
// Temporarily bypass cache to see live changes
// Set "Development Mode" to ON
// ============================================
// PART 10: AUTOMATIC HTTPS REWRITES
// ============================================
// Enable "Automatic HTTPS Rewrites"
// Converts hardcoded http:// links to https://
The steps above demonstrate the lifecycle of a Cloudflare setup: from DNS entry to hardened origin configuration and maintenance tasks.
Quick Reference
Proxy vs. DNS Only
| Feature | DNS Only (Grey) | Proxied (Orange) |
|---|---|---|
| Visibility | Origin IP Exposed | Origin IP Hidden |
| Traffic | Direct to Server | Routed via Edge |
| Security | None | WAF, DDoS, SSL |
| Caching | No | Yes |
SSL/TLS Modes
| Mode | User to Cloudflare | Cloudflare to Origin | Origin Cert |
|---|---|---|---|
| Flexible | HTTPS | HTTP | None |
| Full | HTTPS | HTTPS | Self-Signed OK |
| Full (Strict) | HTTPS | HTTPS | Trusted Required |
Anycast Routing Benefits
| Benefit | Description |
|---|---|
| Speed | Users hit nearest node |
| Reliability | Edge nodes take over if one fails |
| Protection | Volumetric attacks absorbed at edge |
Best Practices
✅ Do This:
# Use "Full (Strict)" SSL mode // ✅
# Install Origin CA cert on your server // ✅
# Trust Cloudflare IPs in your firewall // ✅
# Enable HSTS (Always Use HTTPS) // ✅
# Use page rules to cache static assets // ✅
❌ Don’t Do This:
# Use "Flexible" SSL mode (MITM risk) // ❌
# Expose your raw Origin IP publicly // ❌
# Ignore 'X-Forwarded-For' headers // ❌
# Forget to purge cache after deployment // ❌
# Mix up Grey/Orange cloud settings // ❌
Common Pitfalls
| Pitfall | Why It Happens | Fix |
|---|---|---|
| SSL Redirect Loop | Flexible SSL + HSTS | Switch to Full (Strict) |
| Logged IPs are wrong | Server sees Cloudflare IP | Use mod_remoteip or set_real_ip |
| Origin Unreachable | Firewall blocks Cloudflare | Whitelist Cloudflare IP ranges |
| Cache Stale | Browser sees old version | Purge cache or Dev Mode |
| 403 Forbidden | Origin CA cert issue | Ensure cert is valid and trusted |
Real-World Examples
1. DDoS Mitigation
Absorbing a 500Gbps attack at the edge, protecting the origin from downtime.
2. Geographic Caching
Serving static images for a user in London from a London data center.
3. WAF Rules
Blocking all requests to /admin that do not originate from your corporate VPN IP.
4. SSL Termination
Handling the complexity of managing SSL certs entirely at the Cloudflare edge.
5. Automatic Minification
Automatically stripping whitespace and comments from HTML/CSS/JS files.
6. Bot Management
Distinguishing between legitimate Google crawlers and scraping bots.
7. Origin Hiding
Ensuring the origin server is only accessible via Cloudflare IP ranges.
8. Load Balancing
Distributing traffic across multiple origins using Cloudflare Load Balancing.
9. Argo Smart Routing
Using Cloudflare’s private network to route traffic faster than the public internet.
10. Email Obfuscation
Automatically encrypting email addresses on pages to prevent scraper harvesting.
Visual
Traffic Flow (Proxied)
┌──────────────────────────────────────────────┐
│ USER │
│ │ │
│ ▼ │
│ [ CLOUDFLARE EDGE (Anycast) ] │
│ - Security Checks │
│ - SSL Termination │
│ - Cache Lookup │
│ │ │
│ ▼ │
│ [ YOUR ORIGIN SERVER ] │
└──────────────────────────────────────────────┘
SSL Connection Hops
┌──────────────────────────────────────────────┐
│ USER ──(Encrypted)──► CLOUDFLARE ──(Encrypted)──► ORIGIN
│ │
│ Full (Strict) Mode: │
│ Both legs are encrypted and verified. │
│ │
└──────────────────────────────────────────────┘
Anycast DNS Resolution
┌──────────────────────────────────────────────┐
│ USER (NYC) ──► NYC EDGE NODE (1.1.1.1) │
│ USER (TOK) ──► TOK EDGE NODE (1.1.1.1) │
│ │
│ Same IP, different physical location. │
└──────────────────────────────────────────────┘
Summary
| Item | Value |
|---|---|
| Proxy Icon | Orange Cloud |
| Routing Logic | Anycast (Geo-proximity) |
| Best SSL Mode | Full (Strict) |
| Origin Security | Whitelist Cloudflare IPs |
| Header for IP | CF-Connecting-IP |
| Cache Toggle | Development Mode |
Key takeaways:
- The Orange Cloud matters. It is the differentiator that enables WAF, DDoS protection, and SSL termination.
- Anycast is efficient. It reduces latency by ensuring the first network handshake occurs near the user, not your server.
- SSL security is a chain. Never leave a link unencrypted. Always use Full (Strict) to ensure end-to-end security between the user, the edge, and the origin.
- Identity matters. Your origin server needs to know that the visitor is actually a proxy and needs to be configured to trust the proxy’s IP forwarding headers.
- Defense in depth. Use Cloudflare to block bad traffic before it ever touches your server logs, saving server resources.
Remember: Cloudflare is not just a DNS provider; it is an intelligent gateway. Treat it as your first line of defense and your primary performance layer. Always prioritize end-to-end encryption and ensure your origin server is configured to trust the proxy, not just the raw traffic coming from its edge.
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!