Solution:
Root Cause: Origin Firewall Dropping Cloudflare Proxy TCP SYN Packets When a site is proxied through Cloudflare, all client HTTP/HTTPS traffic hits Cloudflare's edge Points of Presence (PoPs) first. Cloudflare then initiates a TCP connection from its edge IP pools to your origin server IP on port 80 or 443. If your origin firewall (e.g., UFW, iptables, Fail2ban, or AWS Security Group / Azure NSG) treats these concentrated incoming requests as a SYN flood or brute-force attack, it drops the TCP SYN packets. Consequently, the 3-way TCP handshake times out, triggering a
522 Connection Timed Out response from Cloudflare.
Step-by-Step Fix: 1 Fetch Current Cloudflare IP Subnets:
Cloudflare publishes its official IPv4 and IPv6 ranges. Download the latest list: Copy
bash
curl -s [https://www.cloudflare.com/ips-v4](https://www.cloudflare.com/ips-v4) -o /tmp/cf-v4.txt
curl -s [https://www.cloudflare.com/ips-v6](https://www.cloudflare.com/ips-v6) -o /tmp/cf-v6.txt
2 Allow Cloudflare IPs in UFW (Ubuntu/Debian):
Loop through the IP subnets and add explicit allow rules for ports 80 and 443: Copy
bash
for ip in $(cat /tmp/cf-v4.txt /tmp/cf-v6.txt); do
sudo ufw allow proto tcp from $ip to any port 80,443 comment 'Cloudflare'
done
sudo ufw reload
3 Allow Cloudflare IPs in iptables (RHEL/CentOS):
Run the following bash loop to insert rules at the top of the INPUT chain: Copy
bash
for ip in $(cat /tmp/cf-v4.txt); do
sudo iptables -I INPUT -p tcp -m multiport --dports 80,443 -s $ip -j ACCEPT
done
4 Configure Security Groups / Cloud Firewalls:
If hosting on AWS EC2, GCP, or Azure, update inbound Security Group rules to explicitly permit TCP ports 80 and 443 from all Cloudflare CIDR blocks. 5 Unban Cloudflare IPs in Fail2ban:
Check if Fail2ban jailed any Cloudflare IP addresses: Copy
bash
sudo fail2ban-client status http-auth
Add Cloudflare CIDRs to the ignoreip directive in /etc/fail2ban/jail.conf to prevent automated blocking.