To identify and list Cloudflare’s IP addresses, here are the detailed steps:
👉 Skip the hassle and get the ready to use 100% working script (Link in the comments section of the YouTube Video) (Latest test 31/05/2025)
Check more on: How to Bypass Cloudflare Turnstile & Cloudflare WAF – Reddit, How to Bypass Cloudflare Turnstile, Cloudflare WAF & reCAPTCHA v3 – Medium, How to Bypass Cloudflare Turnstile, WAF & reCAPTCHA v3 – LinkedIn Article
-
Access the Official Cloudflare IP Ranges Page: Cloudflare regularly publishes its IP address ranges for IPv4 and IPv6. This is the most reliable and up-to-date source.
- IPv4 Ranges:
https://www.cloudflare.com/ips-v4
- IPv6 Ranges:
https://www.cloudflare.com/ips-v6
- IPv4 Ranges:
-
Use Command-Line Tools for Quick Retrieval: You can download these lists directly using
curl
orwget
.- For IPv4:
curl https://www.cloudflare.com/ips-v4
- For IPv6:
curl https://www.cloudflare.com/ips-v6
- To save to a file:
curl https://www.cloudflare.com/ips-v4 -o cloudflare_ipv4.txt
- For IPv4:
-
Integrate into Firewall Rules or WAFs: If you need to allow Cloudflare traffic through your firewall or Web Application Firewall WAF, you typically import these lists. Most firewalls support importing CIDR notation.
- Example Linux
iptables
– conceptual, requires parsing:# This is conceptual. you'd loop through the downloaded list # and add each CIDR. For production, use a script. # iptables -A INPUT -p tcp -m multiport --dports 80,443 -s <CLOUDFLARE_IP_CIDR> -j ACCEPT
- Example Nginx
allow
directive – conceptual:# This also requires parsing the list and adding each IP/CIDR # allow <CLOUDFLARE_IP_CIDR>.
- Example Linux
-
Regularly Update Your Lists: Cloudflare’s IP ranges can change, though not frequently. It’s good practice to automate fetching and updating these lists periodically e.g., monthly if you rely on them for strict firewalling or security policies. This ensures your systems always recognize legitimate Cloudflare traffic.
Understanding Cloudflare’s IP Ranges and Their Significance
Cloudflare operates one of the world’s largest content delivery networks CDNs and cybersecurity platforms.
Its infrastructure relies on a vast network of servers globally, each assigned specific IP addresses.
Knowing and correctly utilizing Cloudflare’s IP ranges is fundamental for various reasons, primarily security, network configuration, and ensuring seamless service delivery for websites utilizing Cloudflare.
These IP addresses are the public-facing endpoints through which all traffic to a Cloudflare-protected website passes.
Why Knowing Cloudflare IP Ranges Matters
Understanding these IP ranges is crucial for system administrators, network engineers, and website owners who want to properly configure their servers and network devices. Without this knowledge, legitimate traffic from Cloudflare could be blocked, leading to service interruptions or security vulnerabilities. It’s about ensuring that your origin server, the true host of your website, only accepts connections that have been thoroughly scrutinized and filtered by Cloudflare’s robust security layers, thus minimizing direct attack vectors. For instance, in 2023, Cloudflare mitigated a record-breaking DDoS attack peaking at 71 million requests per second, demonstrating the sheer volume of traffic it handles, which all flows through these very IP ranges.
How Cloudflare Uses These IPs
Cloudflare uses its IP ranges for several core functions:
- Proxying Traffic: When a user visits a Cloudflare-protected website, their request first hits a Cloudflare IP address. Cloudflare then processes this request, applies security policies, caches content, and forwards the filtered request to the origin server using its own IP address one from its published ranges.
- DDoS Mitigation: By standing in front of your origin server, Cloudflare absorbs and filters malicious traffic, such as Distributed Denial of Service DDoS attacks, before it reaches your infrastructure.
- WAF Web Application Firewall: Cloudflare’s WAF inspects incoming requests for common web vulnerabilities and blocks malicious payloads.
- CDN Content Delivery Network: Cloudflare caches static content on its edge servers identified by these IPs closer to users, improving website load times and reducing the load on origin servers. Cloudflare’s network spans over 300 cities in more than 120 countries, significantly leveraging these IP ranges for localized content delivery.
Securing Your Origin Server with Cloudflare IP Whitelisting
Securing your origin server is paramount when using Cloudflare.
Without proper configuration, an attacker could bypass Cloudflare’s protection by directly targeting your server’s true IP address.
This is often referred to as “bypassing Cloudflare” or “direct-to-origin attacks.” By whitelisting only Cloudflare’s IP ranges, you instruct your server or firewall to exclusively accept incoming connections from Cloudflare, effectively creating a shield.
This practice significantly reduces the attack surface and ensures that all traffic benefits from Cloudflare’s security and performance features. Tls fingerprints
Why Direct-to-Origin Attacks are a Threat
If an attacker discovers your origin server’s real IP address which can sometimes be found in old DNS records, email headers, or even misconfigured subdomains, they can launch attacks directly against it. These attacks could include:
- DDoS Attacks: Overwhelming your server with traffic, leading to downtime.
- Exploitation of Vulnerabilities: Attempting to exploit known software vulnerabilities on your server directly, bypassing Cloudflare’s WAF.
- Data Exfiltration: Trying to access sensitive data without Cloudflare’s monitoring.
In 2022, Cloudflare reported that 30% of their customers experienced an average of 3 or more direct-to-origin attacks monthly, underscoring the severity of this threat.
Implementing IP Whitelisting on Common Systems
Implementing IP whitelisting typically involves configuring your server’s firewall like iptables
on Linux, Windows Firewall, or hardware firewalls or your web server software like Nginx or Apache to only allow traffic from Cloudflare’s published IP ranges.
On Linux using iptables
:
This method involves creating iptables
rules that explicitly allow traffic from Cloudflare IPs and drop all other incoming traffic to your web ports 80 and 443.
-
Download Cloudflare IP lists:
wget -O /tmp/cf_ips_v4.txt https://www.cloudflare.com/ips-v4 wget -O /tmp/cf_ips_v6.txt https://www.cloudflare.com/ips-v6
-
Create an
iptables
script example:
#!/bin/bashClear existing rules use with caution!
iptables -F
iptables -X
iptables -ZSet default policies DROP everything by default
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPTAllow established connections
Iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
Allow SSH port 22 – adjust as needed
iptables -A INPUT -p tcp –dport 22 -j ACCEPT
Allow traffic from Cloudflare IPs for HTTP/HTTPS
for ip in $cat /tmp/cf_ips_v4.txt. do Https bypass
iptables -A INPUT -p tcp -m multiport --dports 80,443 -s $ip -j ACCEPT
done
For IPv6 using ip6tables
ip6tables -F
ip6tables -X
ip6tables -Z
ip6tables -P INPUT DROP
ip6tables -P FORWARD DROP
ip6tables -P OUTPUT ACCEPTIp6tables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
for ip in $cat /tmp/cf_ips_v6.txt. doip6tables -A INPUT -p tcp -m multiport --dports 80,443 -s $ip -j ACCEPT
Log and drop anything else attempting to connect to HTTP/HTTPS
Iptables -A INPUT -p tcp -m multiport –dports 80,443 -j LOG –log-prefix “CLOUD_BYPASS_ATTEMPT: ” –log-level 7
Iptables -A INPUT -p tcp -m multiport –dports 80,443 -j DROP
Save rules for persistence across reboots, depends on your Linux distribution
On Debian/Ubuntu: apt-get install iptables-persistent && netfilter-persistent save
On CentOS/RHEL: service iptables save
Note: Always test firewall rules in a controlled environment. A misconfiguration can lock you out of your server.
On Nginx using allow
directive:
You can configure Nginx to only serve requests from Cloudflare IPs.
- Create an
allow-cloudflare.conf
file:# /etc/nginx/conf.d/allow-cloudflare.conf or similar path # Cloudflare IPv4 allow 103.21.244.0/22. allow 103.22.200.0/22. # ... add all IPv4 ranges from Cloudflare's ips-v4 list # Cloudflare IPv6 allow 2400:cb00::/32. allow 2606:4700::/32. # ... add all IPv6 ranges from Cloudflare's ips-v6 list deny all. # Deny all other IPs
- Include this file in your Nginx
server
block:
server {
listen 80.
listen :80.
listen 443 ssl.
listen :443 ssl.# … other server configurations …
include /etc/nginx/conf.d/allow-cloudflare.conf.
} - Test Nginx configuration and reload:
nginx -t
systemctl reload nginx
It’s vital to regularly update these lists, perhaps through an automated script, as Cloudflare’s IP ranges can occasionally change. Your browser
Automating this process ensures your firewall rules remain current and effective.
Automating Cloudflare IP List Updates for Robust Security
Manually updating Cloudflare IP ranges in your firewall rules or web server configurations can be tedious and prone to human error, especially if you manage multiple servers.
More importantly, it leaves a window of vulnerability between updates.
Automating this process ensures that your origin server’s security configurations are always up-to-date with Cloudflare’s latest IP ranges, providing continuous and robust protection against direct-to-origin attacks.
This automation typically involves a scheduled script that fetches the latest IP lists and applies them to your firewall or web server configuration.
The Need for Automation
Cloudflare’s IP ranges, while relatively stable, are not static. Cloudflare might add new ranges as they expand their infrastructure or optimize their network. If your firewall rules are based on outdated lists, new Cloudflare edge servers might be unable to reach your origin, leading to service disruptions. Conversely, if old, decommissioned Cloudflare IPs are still allowed, they could theoretically be reassigned to other entities, creating a potential loophole. In a survey of IT professionals, 87% indicated that automated security updates were critical or very critical for maintaining their security posture.
Designing an Automated Update Script
A robust automation script should:
- Fetch Latest IPs: Download the current IPv4 and IPv6 lists from
cloudflare.com/ips-v4
andcloudflare.com/ips-v6
. - Validate Data: Ensure the downloaded content is valid and not corrupted.
- Generate Configuration: Dynamically create or modify firewall rules or web server
allow
directives based on the new lists. - Apply Configuration: Safely apply the new rules e.g., using
iptables-restore
or restarting/reloading web servers. - Error Handling & Logging: Log success or failure, and handle potential errors gracefully e.g., revert to old rules if the new ones fail.
- Scheduling: Be scheduled to run periodically e.g., daily or weekly using
cron
.
Example Automation Script Conceptual for iptables
:
This example uses a simple bash
script.
For production, consider more sophisticated error handling, temporary rule sets, and atomic updates.
#!/bin/bash
LOG_FILE="/var/log/cloudflare_ip_update.log"
IPTABLES_SAVE_FILE="/etc/iptables/rules.v4" # Adjust for your system
IP6TABLES_SAVE_FILE="/etc/iptables/rules.v6" # Adjust for your system
echo "$date: Starting Cloudflare IP update..." | tee -a $LOG_FILE
# Download latest IP lists
wget -q -O /tmp/cf_ips_v4_new.txt https://www.cloudflare.com/ips-v4
wget -q -O /tmp/cf_ips_v6_new.txt https://www.cloudflare.com/ips-v6
# Check if downloads were successful
if || . then
echo "$date: Error: Failed to download Cloudflare IP lists. Exiting." | tee -a $LOG_FILE
rm -f /tmp/cf_ips_v4_new.txt /tmp/cf_ips_v6_new.txt
exit 1
fi
# Backup current iptables rules
if . then
cp "$IPTABLES_SAVE_FILE" "${IPTABLES_SAVE_FILE}.bak"
echo "$date: Backed up current iptables rules to ${IPTABLES_SAVE_FILE}.bak" | tee -a $LOG_FILE
if . then
cp "$IP6TABLES_SAVE_FILE" "${IP6TABLES_SAVE_FILE}.bak"
echo "$date: Backed up current ip6tables rules to ${IP6TABLES_SAVE_FILE}.bak" | tee -a $LOG_FILE
# Generate new iptables rules
# This is a simplified approach. in a real scenario, you'd integrate this
# with your existing firewall setup rather than overwriting it completely.
# A common approach is to use a dedicated chain for Cloudflare IPs.
# For iptables IPv4
echo "*filter" > /tmp/new_iptables_rules.v4
echo ":INPUT ACCEPT " >> /tmp/new_iptables_rules.v4
echo ":FORWARD ACCEPT " >> /tmp/new_iptables_rules.v4
echo ":OUTPUT ACCEPT " >> /tmp/new_iptables_rules.v4
echo "-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT" >> /tmp/new_iptables_rules.v4
echo "-A INPUT -i lo -j ACCEPT" >> /tmp/new_iptables_rules.v4 # Allow loopback
echo "-A INPUT -p tcp --dport 22 -j ACCEPT" >> /tmp/new_iptables_rules.v4 # Allow SSH
echo "-A INPUT -p tcp -m multiport --dports 80,443 -j CLOUDFLARE_INBOUND" >> /tmp/new_iptables_rules.v4
echo ":CLOUDFLARE_INBOUND - " >> /tmp/new_iptables_rules.v4
for ip in $cat /tmp/cf_ips_v4_new.txt. do
echo "-A CLOUDFLARE_INBOUND -s $ip -j ACCEPT" >> /tmp/new_iptables_rules.v4
done
echo "-A CLOUDFLARE_INBOUND -j LOG --log-prefix 'CLOUD_BYPASS_DROP: ' --log-level 7" >> /tmp/new_iptables_rules.v4
echo "-A CLOUDFLARE_INBOUND -j DROP" >> /tmp/new_iptables_rules.v4
echo "COMMIT" >> /tmp/new_iptables_rules.v4
# For ip6tables IPv6
echo "*filter" > /tmp/new_ip6tables_rules.v6
echo ":INPUT ACCEPT " >> /tmp/new_ip6tables_rules.v6
echo ":FORWARD ACCEPT " >> /tmp/new_ip6tables_rules.v6
echo ":OUTPUT ACCEPT " >> /tmp/new_ip6tables_rules.v6
echo "-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT" >> /tmp/new_ip6tables_rules.v6
echo "-A INPUT -i lo -j ACCEPT" >> /tmp/new_ip6tables_rules.v6
echo "-A INPUT -p tcp --dport 22 -j ACCEPT" >> /tmp/new_ip6tables_rules.v6
echo "-A INPUT -p tcp -m multiport --dports 80,443 -j CLOUDFLARE_INBOUND_V6" >> /tmp/new_ip6tables_rules.v6
echo ":CLOUDFLARE_INBOUND_V6 - " >> /tmp/new_ip6tables_rules.v6
for ip in $cat /tmp/cf_ips_v6_new.txt. do
echo "-A CLOUDFLARE_INBOUND_V6 -s $ip -j ACCEPT" >> /tmp/new_ip6tables_rules.v6
echo "-A CLOUDFLARE_INBOUND_V6 -j LOG --log-prefix 'CLOUD_BYPASS_DROP_V6: ' --log-level 7" >> /tmp/new_ip6tables_rules.v6
echo "-A CLOUDFLARE_INBOUND_V6 -j DROP" >> /tmp/new_ip6tables_rules.v6
echo "COMMIT" >> /tmp/new_ip6tables_rules.v6
# Apply new iptables rules
iptables-restore < /tmp/new_iptables_rules.v4
ip6tables-restore < /tmp/new_ip6tables_rules.v6
# Save rules to persist across reboots if using persistent iptables
if command -v netfilter-persistent &> /dev/null. then
netfilter-persistent save
echo "$date: Saved new iptables rules using netfilter-persistent." | tee -a $LOG_FILE
elif command -v service &> /dev/null && service iptables status &> /dev/null. then
service iptables save
echo "$date: Saved new iptables rules using service iptables save." | tee -a $LOG_FILE
else
echo "$date: Warning: Could not find persistent iptables saving mechanism. Rules may not persist across reboot." | tee -a $LOG_FILE
# Clean up
rm -f /tmp/cf_ips_v4_new.txt /tmp/cf_ips_v6_new.txt /tmp/new_iptables_rules.v4 /tmp/new_ip6tables_rules.v6
echo "$date: Cloudflare IP update finished." | tee -a $LOG_FILE
Scheduling with cron
:
Add an entry to your crontab to run the script regularly. For example, to run daily at 3 AM: Automated endpoint management
Edit crontab
crontab -e
Add this line
0 3 * * * /path/to/your/cloudflare_ip_update_script.sh >/dev/null 2>&1
By automating this process, you ensure that your origin server remains optimally protected with minimal manual intervention, allowing you to focus on other critical aspects of your infrastructure.
Leveraging Cloudflare IP Ranges for Advanced Security Configurations
Beyond basic IP whitelisting for your origin server, understanding Cloudflare’s IP ranges opens up possibilities for more sophisticated security and network configurations.
These advanced uses can further enhance your website’s resilience, improve logging accuracy, and fine-tune traffic management, all while leveraging Cloudflare’s global infrastructure.
It’s about taking full advantage of the partnership between your server and Cloudflare’s edge network.
Geo-IP Filtering and Rate Limiting
While Cloudflare offers powerful geo-blocking and rate-limiting features at its edge, understanding their IP ranges allows you to implement additional layers of defense at your origin.
- Geo-IP Filtering: If you have specific regional compliance requirements or notice persistent attacks originating from particular geographies, you can use Cloudflare’s Geo-IP data available in
CF-IPCountry
header along with their IP ranges. For instance, you might decide that connections originating from Cloudflare and reporting a specific country code are handled differently at your origin e.g., served a localized page, or rate-limited more aggressively. In 2023, Cloudflare reported blocking an average of 121 billion cyber threats per day, a significant portion of which are geo-based. - Rate Limiting: Although Cloudflare provides rate limiting, you might want to implement your own secondary rate limits on specific endpoints after traffic has passed through Cloudflare. By whitelisting Cloudflare IPs, you ensure that your server-side rate limiter accurately counts requests from individual users identified by their real IP, which Cloudflare passes in
CF-Connecting-IP
, rather than counting requests from Cloudflare’s few proxy IPs as a single source. This prevents legitimate traffic from being erroneously blocked by your server’s rate limits.
Accurate IP Logging and Analytics
When Cloudflare proxies traffic, your web server’s access logs will typically show Cloudflare’s IP addresses rather than the original visitor’s IP.
This can distort your analytics, making it difficult to identify real user locations or block malicious actors effectively at the origin.
- Restoring Original Visitor IPs: Cloudflare sends the original visitor’s IP address in the
CF-Connecting-IP
HTTP header orX-Forwarded-For
for older configurations. To ensure your logs reflect the actual client IP, you need to configure your web server Nginx, Apache, IIS to trust Cloudflare’s IP ranges and use these headers to overwrite the remote IP.
Nginx Configuration for Real IP:
# Add to your http or server block
set_real_ip_from 103.21.244.0/22.
set_real_ip_from 103.22.200.0/22.
# ... add all other Cloudflare IPv4 ranges
set_real_ip_from 2400:cb00::/32.
set_real_ip_from 2606:4700::/32.
# ... add all other Cloudflare IPv6 ranges
real_ip_header CF-Connecting-IP. # Or X-Forwarded-For if using older settings
real_ip_recursive on. # Process all X-Forwarded-For IPs if multiple proxies are involved
Apache Configuration for Real IP mod_remoteip:
First, ensure `mod_remoteip` is enabled.
```apache
# Add to your httpd.conf or virtual host config
RemoteIPHeader CF-Connecting-IP
RemoteIPTrustedProxy 103.21.244.0/22
RemoteIPTrustedProxy 103.22.200.0/22
RemoteIPTrustedProxy 2400:cb00::/32
RemoteIPTrustedProxy 2606:4700::/32
After configuring, your web server logs will correctly show the visitor's original IP, making your analytics, security monitoring, and IP-based blocking far more accurate. This level of detail is crucial for security analysts. for example, 94% of cybersecurity incidents in 2023 involved some form of logging analysis.
Understanding Cloudflare's IP Range Structure and Best Practices
Cloudflare's IP ranges are not just random blocks of addresses.
they are carefully managed and optimized to support a massive global network.
Understanding their structure and adhering to best practices when working with these IPs is crucial for maximizing performance, ensuring security, and maintaining the stability of your web applications.
It's about respecting the architecture that keeps a significant portion of the internet running smoothly.
# CIDR Notation Explained
Cloudflare publishes its IP ranges in Classless Inter-Domain Routing CIDR notation.
CIDR is a method for allocating IP addresses and for IP routing.
It replaces the old classful networking system Class A, B, C and allows for more granular allocation of IP addresses.
* Format: `IP_Address/Prefix_Length`
* `IP_Address`: The base IP address of the range.
* `Prefix_Length`: A number indicating how many of the leading bits of the IP address are fixed network part. The remaining bits are available for host addresses within that network.
* Example:
* `192.0.2.0/24`: This means the first 24 bits 192.0.2 are fixed, and the last 8 bits can vary. This range includes 2^32-24 = 2^8 = 256 IP addresses from 192.0.2.0 to 192.0.2.255.
* `2400:cb00::/32`: For IPv6, the prefix length is also indicated. `/32` means the first 32 bits are fixed. IPv6 addresses are much larger 128 bits, so `/32` still represents an enormous number of addresses.
Understanding CIDR is essential because firewall rules and network configurations typically require IP ranges to be specified in this format.
Cloudflare provides its lists directly in CIDR, simplifying implementation.
# Best Practices for Managing Cloudflare IP Lists
1. Always Source from Cloudflare's Official Pages:
* `https://www.cloudflare.com/ips-v4`
* `https://www.cloudflare.com/ips-v6`
* Never rely on third-party lists or outdated information, as this can lead to security gaps or service disruptions. Cloudflare explicitly states these are the *only* IPs you should whitelist.
2. Automate Updates: As discussed, manual updates are error-prone and inefficient. Implement scripts that regularly fetch, parse, and apply the latest IP ranges to your firewall rules or web server configurations. Consider running these scripts daily or weekly.
3. Use a Dedicated Firewall Chain/Rule Set: Instead of scattering Cloudflare IP rules throughout your main firewall configuration, create a dedicated chain e.g., `CLOUDFLARE_INBOUND` and jump to it for traffic on ports 80/443. This makes management, auditing, and updates much cleaner.
# Example iptables chain
iptables -N CLOUDFLARE_INBOUND
# ... add all Cloudflare IPs to CLOUDFLARE_INBOUND chain with -j ACCEPT
# After all Cloudflare IPs, add a DROP rule for anything else in this chain
iptables -A CLOUDFLARE_INBOUND -j DROP
# Then in your main INPUT chain for HTTP/HTTPS traffic
iptables -A INPUT -p tcp -m multiport --dports 80,443 -j CLOUDFLARE_INBOUND
4. Implement Robust Error Handling: Your automation scripts should be resilient. If the download fails, or the new rules cannot be applied, the script should log the error and ideally revert to the last known working configuration to prevent service interruption.
5. Monitor Logs for Bypasses: Regularly review your server's firewall logs for attempts to connect directly to your web ports 80/443 from non-Cloudflare IPs. This indicates a potential bypass attempt and should be investigated. Look for log entries that match the `CLOUD_BYPASS_ATTEMPT` prefix if you implemented the logging rule suggested earlier. A recent security report found that 99% of successful web attacks involve a bypass of some form of perimeter defense.
6. Consider `mod_cloudflare` or `mod_remoteip` for Apache/Nginx: These modules automatically handle the Cloudflare IP whitelisting and real IP restoration, simplifying configuration significantly. While they still rely on Cloudflare's IP lists, they manage the integration more elegantly. However, direct firewall rules provide a stronger security posture by blocking traffic *before* it even reaches your web server.
By adhering to these best practices, you can ensure that your server's interaction with Cloudflare is secure, efficient, and resilient, providing your users with a fast and safe online experience.
Distinguishing Cloudflare IPs from Other CDN/Proxy Services
While Cloudflare is a dominant player, it's essential to understand that other CDN and proxy services also have their own published IP ranges.
Misidentifying or conflating these lists can lead to security vulnerabilities or service disruptions.
Each major service e.g., Akamai, Fastly, Amazon CloudFront, Google Cloud Load Balancers maintains its unique set of IP addresses.
It's crucial to understand why you need to distinguish them and how to manage them independently.
# Why Differentiate?
1. Security Posture: Whitelisting an IP range from a different CDN could inadvertently open a back door if you are exclusively trying to protect your origin with Cloudflare. Each CDN has its own security features, and you're relying on Cloudflare's specific WAF and DDoS protection. Allowing traffic from another CDN's IPs might mean that traffic hasn't passed through Cloudflare's scrutiny.
2. Performance and Routing: Different CDNs have different network topologies and points of presence. While your website might use Cloudflare, other services you integrate like external APIs or payment gateways might use other CDNs. Knowing which IPs belong to which service helps in troubleshooting routing or performance issues.
3. Cost and Billing: If you're paying for a specific CDN service, you want to ensure all your relevant traffic is being routed through it. Distinguishing IPs helps confirm this.
4. Compliance: Certain regulatory requirements might demand specific handling of traffic based on its origin or the proxy it passed through.
# How to Distinguish and Manage
The key to distinguishing and managing these IP lists is to always refer to the official documentation of each respective service.
* Cloudflare:
* IPv4: `https://www.cloudflare.com/ips-v4`
* IPv6: `https://www.cloudflare.com/ips-v6`
* Amazon CloudFront AWS CDN: AWS publishes IP ranges for all its services, including CloudFront, in a JSON file.
* `https://ip-ranges.amazonaws.com/ip-ranges.json`
* You would need to parse this JSON and filter for `service: CLOUDFRONT`.
* Akamai: Akamai typically provides these ranges to customers directly or through their support channels, as they manage a highly distributed and proprietary network.
* Fastly: Fastly provides their IP ranges on their documentation site.
* `https://developer.fastly.com/reference/api/utilities/pops/` or similar, check their latest documentation
* Google Cloud Load Balancers/CDN: Google Cloud's public IPs are also published.
* `https://www.gstatic.com/ipranges/cloud.json`
* You'd need to filter for specific services like Google Front End GFE for load balancers.
Management Strategy:
1. Separate Lists: Maintain separate files or variables for each CDN's IP ranges in your automation scripts.
2. Specific Rules: Apply specific firewall rules or web server configurations for each set of IPs. For example, if you only want Cloudflare to access your web server, only their IPs should be whitelisted for ports 80/443. If you have an internal API that only Google Cloud services should access, you would whitelist Google Cloud IPs for that specific port/service.
3. Clear Documentation: Document which IP ranges are whitelisted for which services and why. This is critical for auditing and troubleshooting.
4. Principle of Least Privilege: Only whitelist the IP ranges that are absolutely necessary for your services to function correctly. Avoid broad whitelisting. For example, if your application is only accessible via Cloudflare, there's no need to whitelist AWS CloudFront IPs for your web server.
By meticulously managing and distinguishing these IP lists, you build a more precise and robust security perimeter around your origin infrastructure, ensuring that only trusted and expected traffic reaches your servers.
Troubleshooting Cloudflare IP Related Issues
Despite best practices and automation, issues related to Cloudflare IP addresses can occasionally arise.
These often manifest as connectivity problems, unexpected blocking, or inaccurate logging.
Efficient troubleshooting requires a systematic approach to identify whether the problem lies with Cloudflare's network, your server's configuration, or something in between.
# Common Symptoms and Their Causes
1. Website is Down or Inaccessible Error 52x:
* Cause: Your origin server is blocking Cloudflare's new IP ranges, or your firewall rules are too restrictive. It could also be a misconfigured DNS record pointing directly to Cloudflare's IP.
* Troubleshooting:
* Check Cloudflare Dashboard: Look for "52x" errors in the Analytics or DNS section.
* Verify Firewall Rules: On your origin server, ensure your firewall e.g., `iptables`, Windows Firewall is configured to *allow* all Cloudflare IPs on ports 80 and 443.
* Check Automation Logs: Review logs for your Cloudflare IP update script to see if the last update failed or if there were any errors.
* Temporarily Disable Firewall Cautiously!: If possible and safe e.g., in a maintenance window, temporarily disable your server's firewall. If the site comes online, your firewall is the culprit. Re-enable it and meticulously review your rules.
* Check Origin IP: Use `dig` or `nslookup` on your domain. Ensure it resolves to a Cloudflare IP, not your origin's true IP.
2. Real Visitor IPs Not Showing in Logs:
* Cause: Your web server Apache, Nginx is not correctly configured to use `CF-Connecting-IP` or `X-Forwarded-For` headers, or the `set_real_ip_from` / `RemoteIPTrustedProxy` directives are incomplete.
* Verify Web Server Config: Double-check your Nginx `real_ip_header`, `set_real_ip_from` or Apache `mod_remoteip`, `RemoteIPHeader`, `RemoteIPTrustedProxy` configurations against Cloudflare's documentation. Ensure all Cloudflare IP ranges are listed.
* Check for Multiple Proxies: If there's another proxy or load balancer *between* Cloudflare and your origin, it might be overwriting the `CF-Connecting-IP` header.
3. Connections from Non-Cloudflare IPs to Web Ports:
* Cause: Your firewall rules are not configured correctly to *drop* non-Cloudflare traffic, or an attacker has found a way to bypass your rules.
* Review Firewall Drop Rules: Ensure your firewall has a default `DROP` policy for incoming traffic on web ports after Cloudflare IPs have been `ACCEPT`ed.
* Check All Interfaces: Verify that firewall rules apply to all relevant network interfaces.
* Scan for Origin IP Leakage: Use tools like `crt.sh`, `securitytrails.com`, or Shodan to see if your origin IP is publicly exposed through old DNS records, subdomains, email headers, or other services.
* Internal Network Check: Ensure there isn't an internal misconfiguration exposing your origin directly.
# Tools and Techniques for Debugging
* `curl -v` or `wget --server-response`: Use these from a different server not your origin to check HTTP headers and responses. You can see which IP the request is coming from and if `CF-Connecting-IP` is present.
* `tcpdump` or `wireshark`: Run these on your origin server to capture incoming traffic on ports 80/443. This will show you the source IP addresses of the connections actually hitting your server. If you see non-Cloudflare IPs, your firewall isn't working as intended.
* Cloudflare `cf-detect` unofficial: A community tool that can help verify if your server is properly configured to accept Cloudflare traffic.
* Cloudflare Diagnostic Center: While not directly for IP ranges, it helps diagnose connectivity issues between Cloudflare and your origin: `https://www.cloudflare.com/diagnostic-center/`
* Cloudflare Trace formerly `cloudflare.com/cdn-cgi/trace`: When accessed through a Cloudflare-protected site, it shows the Cloudflare datacenter, your client IP as seen by Cloudflare, and whether the connection is proxied. This can help verify your client-side connection to Cloudflare.
* Server Logs: Always check your web server access logs Apache `access_log`, Nginx `access.log` and firewall logs `/var/log/syslog` or `dmesg` for `iptables` logs for clues.
By methodically checking these points and utilizing the right tools, you can quickly diagnose and resolve most issues related to Cloudflare IP ranges, ensuring your website remains secure and accessible.
Cloudflare's IP Ranges in the Context of Zero Trust Architectures
# The Shift from Perimeter to Zero Trust
Historically, security focused on building a strong perimeter, like a castle wall. Once inside, everything was implicitly trusted.
Cloudflare's IP whitelisting for origin servers is a classic example of strengthening this perimeter.
However, this model struggles when assets are distributed across clouds, users access resources from anywhere, and internal threats become more prevalent.
Zero Trust operates on several key principles:
1. Verify Explicitly: Authenticate and authorize every device, user, and application before granting access, regardless of their location.
2. Least Privilege Access: Grant users only the minimum access needed to perform their tasks.
3. Assume Breach: Always operate as if an attacker is already present within the network.
4. Monitor Continuously: Inspect and log all traffic.
# Cloudflare IPs in a Hybrid Security Model
* Perimeter Hardening for Traditional Web Assets: For classic web servers and applications that still reside in a datacenter or a traditional cloud VM, whitelisting Cloudflare's IP ranges remains an essential security measure. It's the most effective way to ensure that external requests to your web application are *always* filtered through Cloudflare's DDoS protection, WAF, and other edge services. In this context, the Cloudflare IP is a 'trusted proxy' that has already performed the initial verification. This doesn't contradict Zero Trust, but rather is a layer *before* deeper, identity-based verification.
* Transitioning to Identity-Based Access: Cloudflare itself offers Zero Trust solutions, notably Cloudflare Zero Trust formerly Cloudflare Access. This platform allows organizations to control access to applications based on user identity, device posture, and other contextual signals, rather than just network location. When using Cloudflare Zero Trust, your origin server might no longer need to strictly whitelist Cloudflare's public IP ranges. Instead, the connection from Cloudflare's Zero Trust network to your origin could use specific, private, or application-specific tunnels, or it could still use a subset of Cloudflare's internal IPs that are trusted for Zero Trust access, but the *external* IP that users connect to is no longer the sole source of trust.
* Layered Security: Think of Cloudflare's IP whitelisting as the first layer of explicit verification for your web application. It ensures that only traffic coming from Cloudflare's intelligent network can even *attempt* to reach your origin. *After* that, your application layer should still implement its own authentication, authorization, and session management, adhering to Zero Trust principles by verifying the user's identity and permissions *every time*. This is where Cloudflare's `CF-Connecting-IP` header becomes crucial for your application to explicitly verify the original client.
# Best Practices in a Zero Trust World
Even with Zero Trust, Cloudflare IP lists remain relevant for specific purposes:
* Explicit Trust for Edge Services: Your origin explicitly trusts Cloudflare's public IP ranges because Cloudflare is performing critical security functions DDoS, WAF, Bot Management on its behalf. This trust is *explicit* and *verified* by your firewall.
* Logging and Observability: Ensuring accurate IP logging using the `CF-Connecting-IP` header is critical for Zero Trust. Continuous monitoring and granular logging of all traffic, including the original client IP, is a core Zero Trust principle.
* Reducing Attack Surface: By blocking all non-Cloudflare IP traffic at the network edge of your origin, you dramatically reduce the attack surface. This allows your Zero Trust policies to focus on verifying *authorized* traffic and users, rather than expending resources on filtering raw malicious traffic.
In essence, while Zero Trust advocates for granular, identity-driven access, Cloudflare's public IP ranges serve as a powerful initial filter, ensuring that the traffic even *considered* for Zero Trust policies has already passed through a robust global security network. They complement, rather than contradict, a comprehensive Zero Trust strategy, especially for public-facing web applications.
Frequently Asked Questions
# What are Cloudflare IP addresses?
Cloudflare IP addresses are the public-facing IP ranges both IPv4 and IPv6 used by Cloudflare's global network of servers to proxy, protect, and optimize websites.
When a website uses Cloudflare, all visitor traffic goes through these IP addresses before reaching the origin server.
# Where can I find the official list of Cloudflare IP ranges?
You can find the official and most up-to-date lists of Cloudflare IP ranges directly from Cloudflare's website:
* IPv4: `https://www.cloudflare.com/ips-v4`
* IPv6: `https://www.cloudflare.com/ips-v6`
# Why do I need to whitelist Cloudflare's IP addresses on my server?
You need to whitelist Cloudflare's IP addresses on your origin server's firewall to ensure that your server only accepts legitimate traffic that has passed through Cloudflare's security and optimization layers.
This prevents attackers from bypassing Cloudflare's protection and directly targeting your server's true IP address.
# How often do Cloudflare's IP addresses change?
Cloudflare's IP addresses do not change frequently, but they can be updated or expanded as Cloudflare grows its infrastructure.
It's considered a best practice to check for updates periodically e.g., daily or weekly and automate the process of refreshing your firewall rules to ensure they are always current.
# Can I just block all traffic except Cloudflare IPs on ports 80 and 443?
Yes, this is generally recommended and is a strong security measure.
By blocking all traffic on ports 80 HTTP and 443 HTTPS that doesn't originate from Cloudflare's official IP ranges, you create a "Walled Garden" effect, ensuring all web traffic passes through Cloudflare's security services.
# What is CIDR notation, and why is it used for Cloudflare IPs?
CIDR Classless Inter-Domain Routing notation is a standardized way to represent IP address ranges.
It consists of an IP address followed by a slash and a prefix length e.g., `192.0.2.0/24`. Cloudflare uses CIDR because it's an efficient and widely recognized method for specifying network blocks, making it easy to integrate into firewalls and network configurations.
# My website is showing a 521 error. Is it related to Cloudflare IPs?
A 521 error "Web server is down" often indicates that your origin server is refusing connections from Cloudflare.
This is a common symptom of misconfigured firewall rules that block Cloudflare's IP ranges.
You should check your server's firewall to ensure Cloudflare IPs are allowed.
# How can I make my web server logs show the real visitor IP instead of Cloudflare's IP?
Cloudflare passes the original visitor's IP address in the `CF-Connecting-IP` HTTP header.
You need to configure your web server e.g., Nginx with `set_real_ip_from` and `real_ip_header`, or Apache with `mod_remoteip` and `RemoteIPHeader` to read and use this header to restore the real client IP in your access logs.
# Are Cloudflare's IP ranges the same for all customers?
Yes, the published Cloudflare IP ranges are global and apply to all customers using their proxy service, regardless of their plan level.
These are the public IPs of Cloudflare's edge network that clients connect to.
# Can I manually add Cloudflare IPs to my firewall rules?
Yes, you can manually add them, but it's highly recommended to automate this process.
Manual updates are prone to errors, time-consuming, and can lead to security gaps if you miss new ranges or don't remove old ones.
# What happens if I don't whitelist Cloudflare IPs?
If you don't whitelist Cloudflare IPs, your server might block legitimate traffic from Cloudflare's network, leading to website downtime e.g., 521 errors. More critically, it leaves your origin server vulnerable to direct attacks that bypass Cloudflare's protection.
# Does Cloudflare itself provide a tool to check my firewall configuration?
Cloudflare provides diagnostic tools within its dashboard and publicly available tools like Cloudflare Trace `cloudflare.com/cdn-cgi/trace` that can help verify if your site is being proxied correctly. While they don't directly check your *firewall rules*, they can indicate if Cloudflare is having trouble connecting to your origin.
# What if I have multiple web servers behind a load balancer?
If you have multiple web servers behind a load balancer, the load balancer typically needs to whitelist Cloudflare's IPs, and then the load balancer forwards traffic to your individual web servers.
Your web servers might then only need to trust the IP address of your load balancer, simplifying their individual firewall rules.
# Is it secure to expose my true origin IP to Cloudflare?
Yes, it is secure to expose your true origin IP to Cloudflare. Cloudflare acts as a reverse proxy, and only Cloudflare's network will directly connect to your origin server. The rest of the world will only see Cloudflare's IPs. The key is to only allow Cloudflare IPs to connect to your web ports on your origin.
# Can direct-to-origin attacks still happen if I whitelist Cloudflare IPs?
Direct-to-origin attacks are significantly harder if you correctly whitelist Cloudflare IPs.
However, they can still occur if your true origin IP leaks through other means e.g., old DNS records, email server configurations, misconfigured subdomains, or through services like FTP/SSH that are publicly accessible on your origin IP.
# Should I also whitelist Cloudflare IPs for other services like SSH or FTP?
No, you should not whitelist Cloudflare IPs for services like SSH or FTP. Cloudflare only proxies HTTP/S traffic ports 80 and 443. SSH port 22 and FTP ports 20, 21 should be secured differently, ideally by allowing access only from known administrative IPs or by using VPNs.
# What is the difference between Cloudflare's "trusted proxies" and regular IP ranges?
Cloudflare's published IP ranges are its "trusted proxies." These are the addresses that will connect to your origin server. There isn't a separate distinction.
these are the ranges you need to whitelist for your web traffic.
# How does Cloudflare's IP whitelisting relate to a Zero Trust security model?
Cloudflare's IP whitelisting hardens the perimeter for traditional web applications, ensuring that all incoming web traffic is verified by Cloudflare first.
In a Zero Trust model, this acts as an initial, explicit verification layer, reducing the attack surface before further identity-based authentication and authorization policies are applied at the application layer.
# What if my hosting provider automatically manages Cloudflare IPs?
Some hosting providers or managed WordPress services may automatically handle Cloudflare IP whitelisting for you. It's important to confirm this with your provider.
If they do, you generally don't need to manually configure your server's firewall for Cloudflare IPs, but you should still ensure direct access to your origin is blocked.
# Can I use a script to automatically update Cloudflare IP ranges in my Nginx configuration?
Yes, you can create a script that downloads the latest Cloudflare IP lists, dynamically generates the `allow` directives for Nginx, and then includes this file in your Nginx configuration.
After updating the file, the script should trigger a `nginx -t` test config and `systemctl reload nginx` to apply the changes without downtime.
Leave a Reply