Cloudflare Origin Security: Protect Your Server
Compare Cloudflare origin protection methods. Secure your server by configuring IP allowlists and WAF rules to block direct access.

On this page
TL;DR — Key takeaways
- Enable 'Always Use HTTPS' and 'Hide Cloudflare' to prevent direct origin access via DNS leaks.
- Configure firewall rules to allow traffic only from Cloudflare IP ranges, blocking all other direct connections.
- Use the 'Under Attack' mode sparingly; it adds latency and is not a permanent security solution.
- Regularly audit your server logs for non-Cloudflare IPs to detect origin IP leaks.
Protecting your origin server is a fundamental security practice when using Cloudflare. If your server IP is exposed, attackers can bypass Cloudflare's protections and directly target your infrastructure.
This guide compares the main methods for securing your origin server and provides a clear recommendation based on practical operational experience. We'll cover the trade-offs of each approach and how to implement them effectively.
Understanding Origin Server Exposure
When you use Cloudflare, your website's DNS records point to Cloudflare's IP addresses. This means users access your site through Cloudflare's network, not directly to your server. However, your origin server still has a public IP address that can be discovered through various methods.
If an attacker finds your origin IP, they can bypass Cloudflare's DDoS protection, WAF rules, and other security features. This direct access can lead to data breaches, server compromise, or service disruption. Understanding this risk is the first step in protecting your infrastructure.
- Origin IP exposure allows attackers to bypass Cloudflare protections
- Direct access can lead to data breaches and server compromise
- Understanding the risk is essential for effective security
Method 1: Cloudflare Firewall Rules
The most effective method is to configure firewall rules on your origin server to only accept traffic from Cloudflare's IP ranges. This approach ensures that all traffic must pass through Cloudflare, maintaining the security benefits of the proxy.
To implement this, you need to obtain Cloudflare's current IP ranges and configure your server's firewall (e.g., iptables, ufw, or security groups) to allow traffic only from those ranges. This method is highly effective but requires ongoing maintenance as Cloudflare updates its IP ranges.
- Highly effective at blocking direct access
- Requires ongoing maintenance of IP ranges
- Ensures all traffic passes through Cloudflare
Method 2: Cloudflare WAF Rules
Cloudflare's Web Application Firewall (WAF) can also be used to protect your origin server. By creating custom WAF rules, you can block traffic that doesn't match expected patterns or comes from suspicious sources.
While WAF rules are powerful, they are not a complete solution for origin protection. Attackers can still bypass WAF rules if they have direct access to your origin IP. WAF is best used as an additional layer of defense, not as the primary protection method.
- Adds an additional layer of defense
- Not a complete solution for origin protection
- Best used in conjunction with firewall rules
Method 3: 'Under Attack' Mode
Cloudflare's 'Under Attack' mode is a temporary measure that challenges visitors with a JavaScript test before allowing access. While it can slow down automated attacks, it is not a permanent security solution.
This mode adds latency to all visitors and can negatively impact user experience. It should only be used during active attacks and disabled as soon as the threat subsides. Relying on 'Under Attack' mode as a primary security measure is not recommended.
- Temporary measure for active attacks
- Adds latency and impacts user experience
- Not a permanent security solution
Comparison and Recommendation
When comparing these methods, firewall rules on your origin server provide the most robust protection. They ensure that all traffic must pass through Cloudflare, maintaining the security benefits of the proxy. WAF rules and 'Under Attack' mode are useful as additional layers of defense but should not be relied upon as the primary protection method.
For most users, the recommended approach is to implement firewall rules on your origin server to allow traffic only from Cloudflare's IP ranges. This method is highly effective and provides a clear security boundary. Supplement this with WAF rules for additional protection and use 'Under Attack' mode only during active attacks.
- Firewall rules provide the most robust protection
- WAF rules add an additional layer of defense
- 'Under Attack' mode is for temporary use only
Implementation and Verification
To implement the recommended approach, start by obtaining Cloudflare's current IP ranges. Configure your server's firewall to allow traffic only from those ranges. Then, test direct access to your origin IP to confirm that it is blocked.
Regularly audit your server logs for non-Cloudflare IPs to detect origin IP leaks. This ongoing monitoring ensures that your protection remains effective and helps identify any potential vulnerabilities.
- Obtain Cloudflare's current IP ranges
- Configure firewall to allow only Cloudflare traffic
- Test direct access to confirm blocking
- Regularly audit server logs for non-Cloudflare IPs
Quick troubleshooting checklist
- Verify all DNS records are proxied (orange cloud) in Cloudflare.
- Add a firewall rule to block all traffic except from Cloudflare IP ranges.
- Enable 'Always Use HTTPS' to force secure connections.
- Test direct access to your origin IP to confirm it is blocked.
- Monitor server logs for unauthorized direct connections.
FAQ
What is the primary method to protect a Cloudflare origin server?
The primary method is to configure firewall rules on your origin server to only accept traffic from Cloudflare's IP ranges, effectively blocking all direct connections from other sources.
How can I check if my origin server IP is exposed?
You can check by attempting to access your website directly using your origin server IP address instead of the domain name. If the site loads, your IP is exposed and needs protection.
Does Cloudflare automatically hide my origin server IP?
Cloudflare proxies traffic, which hides your IP from most users, but it does not automatically block direct access to your origin server. You must configure firewall rules to enforce this protection.
Related articles
- Infrastructure SecurityHow to Hide Your Origin Server Behind Cloudflare: A Hosting Support ChecklistLearn how to protect an origin server behind Cloudflare with DNS checks, firewall allowlists, tunnels, SSL, and direct-IP bypass testing.
- Hosting OperationsCloudflare Too Many Redirects: 7 Fixes That Work (2026)Fix Cloudflare too many redirects by comparing SSL modes, origin rules, and page rules. Clear steps for each cause with rollback safety.
- Hosting OperationsHow to fix Cloudflare 525 SSL handshake failed: Security Hardening GuideResolve Cloudflare 525 SSL handshake errors with security-focused troubleshooting, hardening steps, and configuration verification methods.
- Hosting OperationsCloudflare 525 SSL Handshake Failed: Causes and Solutions - Security Hardening GuideFix Cloudflare 525 SSL handshake errors with this security-focused guide. Learn root causes, audit steps, hardening best practices, and verification methods.
- Hosting OperationsCloudflare Tomorrow Watchlist: A Practical Hosting Operations GuidePractical Cloudflare troubleshooting checklist for DNS, SSL, caching, WAF, origin health, safe testing, and rollback planning.
- Hosting OperationsCloudflare Updates: What Site Owners Should KnowCompare the latest Cloudflare changes that affect latency and security. See what matters for your site, what to test, and what to leave alone.