Many website owners and digital businesses in Pakistan believe that simply routing their domain through Cloudflare, Fastly, or an edge Web Application Firewall (WAF) makes them immune to volumetric DDoS attacks and web exploits. They install security plugins, configure WAF rules, and relax—only to find their origin server suddenly crashing under a mysterious flood or compromised via a direct SQL injection exploit.
The cause is almost always Origin IP Exposure and WAF Bypass. If an attacker discovers your real backend server IP address through historical DNS records (Censys, Shodan, SecurityTrails), unscrubbed outbound email headers, SSL certificate SAN leaks, or direct ping probes, they bypass your edge WAF entirely! The attacker sends malicious HTTP payloads directly to https://203.0.113.10:443/, completely skipping Cloudflare’s WAF and overwhelming your cPanel Apache server.
Hardening your origin requires a strict zero-trust strategy: cloaking DNS records, scrubbing outbound mail headers, configuring iptables/CSF to strictly allow Cloudflare proxy IPs, and restoring client visitor IPs via Apache’s mod_remoteip.
In this guide, we walk through origin IP cloaking on Cloud VPS instances and enterprise Dedicated Servers.
1. Anatomy of an Origin Bypass Attack
When your origin IP is exposed, edge WAF defenses are rendered completely useless:
+--------------------------------------------------------------------------+
| WAF EDGE VS. DIRECT ORIGIN EXPLOITATION |
+--------------------------------------------------------------------------+
| SCENARIO A: Legitimate User Traverses Cloudflare WAF |
| Client Browser ──► Cloudflare Edge (WAF Inspects & Scrubs) ──► Origin Server
| Protection: 100% Active |
| |
| SCENARIO B: Attacker Bypasses Edge via Exposed Origin IP |
| Attacker ──► Sends Malicious SQLi / SYN Flood directly to: 203.0.113.10:443|
| Result: Edge WAF completely bypassed! Origin server crashes or is rooted |
+--------------------------------------------------------------------------+
2. Closing the Origin Leak Vectors
Before locking down your firewall, audit and plug the common information leaks that reveal your origin IP to automated internet crawlers:
Leak 1: Outbound Mail Headers
When WordPress sends password resets or WooCommerce order notifications via standard PHP mail(), the raw outbound SMTP headers reveal the server’s public IP:
Received: from server.yourhost.pk ([203.0.113.10]) ...
Fix: Never send outbound mail directly from your web origin IP. Route all transactional email through a dedicated third-party SMTP relay (Sendgrid, Postmark, Amazon SES) or an isolated mail node.
Leak 2: Historical DNS & Subdomain Records
Check your domain on Censys or Shodan. If subdomains like mail.yourdomain.pk, cpanel.yourdomain.pk, or ftp.yourdomain.pk point directly to your origin server without an orange Cloudflare proxy cloud, bots immediately map the IP to your main domain!
Fix: Move administrative access and mail handling to separate IP subnets or non-standard subdomains protected by Access VPNs.
3. Kernel & Firewall Lockdown: Allowing ONLY Cloudflare Edge IPs
The single most effective defense against WAF bypass is configuring your host firewall to DROP any direct connection on HTTP/HTTPS ports (80/443) that does NOT originate from Cloudflare’s verified IP ranges.
Step 1: Automated CSF / iptables Sync Script
If running CSF Firewall on cPanel/WHM, automate Cloudflare IP synchronization via a nightly bash script:
Create /usr/local/bin/sync-cloudflare-ips.sh:
#!/bin/bash
# Fetch latest IPv4 and IPv6 ranges from official Cloudflare API
CF_IPV4=$(curl -s https://www.cloudflare.com/ips-v4)
CF_IPV6=$(curl -s https://www.cloudflare.com/ips-v6)
TEMP_FILE="/tmp/cf_ips.txt"
echo "# Cloudflare Verified Edge IPs" > $TEMP_FILE
for ip in $CF_IPV4; do
echo "tcp|in|d=80,443|s=$ip" >> $TEMP_FILE
done
# If using iptables directly:
# Flush custom chain
iptables -N CLOUDFLARE_LOCKDOWN 2>/dev/null || iptables -F CLOUDFLARE_LOCKDOWN
for ip in $CF_IPV4; do
iptables -A CLOUDFLARE_LOCKDOWN -p tcp -m multiport --dports 80,443 -s $ip -j ACCEPT
done
# Drop all direct attempts to ports 80/443 from any other IP!
iptables -A CLOUDFLARE_LOCKDOWN -p tcp -m multiport --dports 80,443 -j DROP
# Insert at top of INPUT chain
iptables -C INPUT -p tcp -m multiport --dports 80,443 -j CLOUDFLARE_LOCKDOWN 2>/dev/null || \
iptables -I INPUT 1 -p tcp -m multiport --dports 80,443 -j CLOUDFLARE_LOCKDOWN
Make it executable and test:
sudo chmod +x /usr/local/bin/sync-cloudflare-ips.sh
sudo /usr/local/bin/sync-cloudflare-ips.sh
Now, if an attacker attempts to browse directly to https://203.0.113.10/, their TCP handshake is dropped silently at the kernel level with zero response!
4. Restoring Client IPs in Apache via mod_remoteip
Because all legitimate traffic now arrives from Cloudflare reverse proxy IPs, Apache access logs and PHP variables ($_SERVER['REMOTE_ADDR']) would normally record Cloudflare’s IP addresses instead of the authentic visitor’s IP.
Enable Apache’s mod_remoteip in cPanel/WHM:
- In WHM, ensure
ea-apache24-mod_remoteipis installed via EasyApache 4. - Create
/etc/apache2/conf.d/includes/pre_main_global.conf:
# /etc/apache2/conf.d/includes/pre_main_global.conf
<IfModule remoteip_module>
RemoteIPHeader CF-Connecting-IP
# Trust Cloudflare IPv4 Edge Ranges
RemoteIPTrustedProxy 173.245.48.0/20
RemoteIPTrustedProxy 103.21.244.0/22
RemoteIPTrustedProxy 103.22.200.0/22
RemoteIPTrustedProxy 103.31.4.0/22
RemoteIPTrustedProxy 141.101.64.0/18
RemoteIPTrustedProxy 108.162.192.0/18
RemoteIPTrustedProxy 190.93.240.0/20
RemoteIPTrustedProxy 188.114.96.0/20
RemoteIPTrustedProxy 197.234.240.0/22
RemoteIPTrustedProxy 198.41.128.0/17
RemoteIPTrustedProxy 162.158.0.0/15
RemoteIPTrustedProxy 104.16.0.0/13
RemoteIPTrustedProxy 104.24.0.0/14
RemoteIPTrustedProxy 172.64.0.0/13
RemoteIPTrustedProxy 131.0.72.0/22
</IfModule>
Restart Apache:
/usr/local/cpanel/scripts/restartsrv_httpd
Your access logs and security plugins (like Wordfence or iThemes) now receive the genuine visitor’s IP address while your origin server remains completely shielded from direct probes!
5. Testing & Validation
Test direct access from an external terminal:
# Attempt direct curl to origin IP bypassing DNS
curl -I -k https://203.0.113.10/
The connection should immediately hang or time out (Dropped).
Now test through the domain via Cloudflare:
curl -I https://yourdomain.pk/
Returns a crisp HTTP/2 200 OK, confirming that only traffic vetted and sanitized by your edge WAF can reach your origin server!
6. Enterprise Resiliency
Origin cloaking protects your core web assets from automated scanners and volumetric layer-7 floods.
Explore our related security and server administration tutorials:
- ModSecurity OWASP CRS Tuning on cPanel
- Fail2ban Custom Jails for SSH & cPanel Hardening
- Linux eBPF & XDP DDoS Mitigation at Wire Speed
For corporate portals, fintech platforms, and e-commerce leaders requiring unshared bare-metal computing and custom hardware firewall protection, deploy on Dedicated Servers in Pakistan.
Deploy Cloaked & Hardened Infrastructure with Nextgen
Protect your web applications with origin IP cloaking, hardware DDoS scrubbing, and low-latency peering across Pakistan.
