Skip to main content

How to Allow Cloudflare IP Ranges Through a Server Firewall

This article explains how to configure your server's firewall to permit traffic from Cloudflare's IP addresses. This is necessary when your server is behind Cloudflare's proxy to ensure that Cloudflare can successfully communicate with your origin server.

This article explains how to configure your server's firewall to permit traffic from Cloudflare's IP addresses. This is necessary when your server is behind Cloudflare's proxy to ensure that Cloudflare can successfully communicate with your origin server.

Important: This procedure is required if you use Cloudflare's "Proxied" (orange cloud) status for your DNS records. If you do not allow these IPs, your server may block Cloudflare's requests, resulting in errors such as 522 (Connection Timed Out) or 524 (A Timeout Occurred).

Before you begin

You will need:

  • Administrative access to your server's firewall (e.g., iptables, firewalld, or a hardware firewall).

  • The current list of Cloudflare IP ranges.

Allow Cloudflare IP ranges in your firewall

To ensure your server accepts traffic from Cloudflare, you must add their specific IP ranges to your firewall's "allow" list.

  1. Obtain the current list of Cloudflare IP ranges from the official Cloudflare documentation.

  2. Access your server's firewall configuration interface or command line.

  3. Add the Cloudflare IP ranges to your allowed list.

  4. Save the configuration and apply the changes.

Warning: Incorrectly configuring firewall rules can block legitimate traffic or leave your server exposed to unauthorized access. Always verify your rules before applying them to a production environment.

Confirm the result

To verify that the firewall is correctly configured:

  • Test your website's availability through the Cloudflare proxy.

  • Check your server's access logs to confirm that requests from Cloudflare IP addresses are being accepted and processed.

  • Ensure that your server's firewall is not dropping packets from the Cloudflare IP range.

Limitations

  • This procedure only addresses the firewall layer. It does not replace the need for proper security configurations on the web server software (e.g., Nginx or Apache).

  • The specific commands or interface steps vary depending on your server's operating system and firewall software.

  • If you use a third-party firewall or a Web Application Firewall (WAF) provided by a different service, you must update the rules within that specific service's management console.

Did this answer your question?