Skip to content
Back to Blog
Security10 min read

How to Protect Your Origin Server Behind Cloudflare: Hide Your Real IP

Putting your site behind Cloudflare does not help if attackers can find your origin server's real IP and bypass it entirely. Learn how origin IPs leak — through DNS history, SSL scans, mail headers, and unproxied records — and how to lock your origin down so only Cloudflare can reach it.

Written by Abdul AbrorTechnical Hosting Support Engineer
On this page

Putting your website behind Cloudflare feels like flipping a security switch — DDoS protection, a WAF, and a hidden IP, all at once. But there is a catch most site owners never check: if attackers can discover your origin server's real IP address, they can bypass Cloudflare entirely and hit your server directly. This guide explains exactly how origin IPs leak, how to verify whether yours is exposed, and the concrete steps to lock your origin down so Cloudflare actually protects it.

Why Hiding Your Origin IP Matters

When you proxy your domain through Cloudflare (the orange cloud in your DNS settings), visitors connect to Cloudflare's edge network instead of your server. Cloudflare filters malicious traffic, then forwards legitimate requests to your origin. The protection only works as long as one assumption holds: attackers do not know your origin's real IP address.

If that IP leaks, an attacker can send traffic straight to your server, skipping Cloudflare's WAF and DDoS mitigation. Your “protected” site is then exactly as exposed as it was before you signed up. This is one of the most common — and most overlooked — misconfigurations in shared hosting and VPS setups.

How Attackers Find Your Origin IP

According to Cloudflare's own documentation and security research from Detectify, there are several well-known ways an origin IP gets discovered. Understanding them is the first step to closing the gaps.

1. Historical DNS records

DNS records are public by nature. Even after you enable the Cloudflare proxy, services that archive DNS history may still hold the old A record that pointed directly to your server before Cloudflare was added. An attacker simply looks up your domain's DNS history and reads the original IP.

2. SSL certificate scanning

Services continuously scan the entire internet on port 443 and log which IP serves a certificate for which domain. If your origin server still presents a certificate for your domain directly, a certificate search engine can reveal the IP hosting it — completely bypassing DNS.

3. Unproxied (DNS-only) records

This is the most common leak. Records like ftp.yourdomain.com, cpanel.yourdomain.com, mail.yourdomain.com, or a leftover direct.yourdomain.com are often left as DNS-only (grey cloud) because they cannot be proxied. Each one publicly resolves to your origin IP.

4. Email headers

Cloudflare does not proxy email. When your server sends an email — a password reset, an order confirmation, or a bounce message to a non-existent address — the message headers frequently contain the sending server's real IP. An attacker only has to trigger one email and read the headers.

5. Subdomain enumeration

Attackers brute-force common subdomain names looking for one that was never proxied. Development, staging, and admin subdomains are frequent offenders because they are set up quickly and forgotten.

How to Check If Your Origin IP Is Exposed

Before fixing anything, find out what is currently leaking. Work through this audit:

  1. Review every DNS record. In your Cloudflare dashboard, open DNS → Records. Look at every A and AAAA record. Any record showing a grey cloud (DNS-only) is publicly exposing whatever IP it points to.
  2. Check your mail records. MX records and the A record they point to (often mail.) usually expose the IP. If your mail server runs on the same machine as your website, that IP is your origin.
  3. Search certificate transparency logs. Look up your domain on a certificate search service and note any IP serving a certificate for your domain outside of Cloudflare.
  4. Test direct access. If you know your server IP, try opening https://YOUR_ORIGIN_IP/ in a browser. If your website loads, your origin is accepting connections from anyone — not just Cloudflare.

The Fix: Allow Only Cloudflare to Reach Your Origin

Hiding the IP is helpful, but the real guarantee is to configure your origin so it only accepts connections from Cloudflare. Even if an attacker discovers your IP, the server simply refuses their traffic. Cloudflare's official guidance recommends exactly this approach.

Option A: Firewall allowlist (VPS / root access)

If you manage your own server, configure the firewall to deny all inbound web traffic except from Cloudflare's published IP ranges. Cloudflare maintains the current list at cloudflare.com/ips. With ufw on Ubuntu, the pattern looks like this:

# Default: deny incoming web traffic
sudo ufw default deny incoming

# Allow HTTP/HTTPS ONLY from Cloudflare ranges
# (repeat for every range listed at cloudflare.com/ips)
for ip in $(curl -s https://www.cloudflare.com/ips-v4); do
  sudo ufw allow from $ip to any port 443 proto tcp
  sudo ufw allow from $ip to any port 80 proto tcp
done

# Keep your own SSH access on a separate rule
sudo ufw allow from YOUR_ADMIN_IP to any port 22 proto tcp

sudo ufw enable

After this, any request to ports 80/443 that does not originate from Cloudflare is dropped. Remember to re-check the IP list periodically — Cloudflare does update it.

Option B: Authenticated Origin Pulls (mTLS)

For a cryptographic guarantee rather than an IP-based one, enable Authenticated Origin Pulls. This makes Cloudflare present a client certificate when it connects to your origin, and your server rejects any connection that does not present that certificate. Even traffic from a spoofed Cloudflare IP fails. You enable it under SSL/TLS → Origin Server → Authenticated Origin Pulls in Cloudflare, then configure your web server to require the Cloudflare origin certificate.

Option C: Shared hosting (cPanel without root)

On shared hosting you usually cannot edit the server firewall, but you still have options:

  • Use an .htaccess rule to reject requests that did not pass through Cloudflare, by checking for the CF-Connecting-IP header and allowlisting Cloudflare ranges with mod_remoteip where available.
  • Ask your hosting provider whether they support allowlisting Cloudflare IPs at the server firewall — many cPanel hosts can apply this for you on request.
  • Set Cloudflare SSL mode to Full (Strict) so the connection between Cloudflare and your origin is encrypted and certificate-validated end to end.

Plugging the Common Leaks

Locking the firewall handles direct attacks, but you should still close the information leaks so your IP is not trivially discoverable:

  • Proxy everything you can. Switch grey-cloud records to orange where possible. Records that truly cannot be proxied (like MX) should point to a different IP than your web origin.
  • Separate your mail server. Run email on a different host or use a third-party email service so a bounced message never reveals your web origin.
  • Remove stale subdomains. Delete old dev., staging., old., and direct. records that point straight at your server.
  • Rotate the IP if it already leaked. If your origin IP was public before you added Cloudflare, the historical record already exists. The only complete fix is to move your origin to a new IP and apply the firewall allowlist so the old one is useless even if found.

Origin Protection Checklist

  1. All web A/AAAA records proxied (orange cloud)
  2. No grey-cloud record points to the web origin IP
  3. Mail server runs on a separate IP or external provider
  4. Stale dev/staging/direct subdomains removed
  5. Firewall allows ports 80/443 only from Cloudflare IP ranges
  6. SSH/admin access restricted to your own IP
  7. SSL mode set to Full (Strict)
  8. Authenticated Origin Pulls enabled (if supported)
  9. Direct access to https://ORIGIN_IP/ no longer serves your site
  10. Cloudflare IP allowlist scheduled for periodic review

Conclusion

Cloudflare is only as strong as your origin configuration. The orange cloud hides your IP from casual lookups, but real protection comes from making your server refuse any connection that did not arrive through Cloudflare. Audit your DNS records, separate your mail server, remove stale subdomains, and allowlist Cloudflare's IP ranges at your firewall. Do those four things and an attacker who discovers your origin IP gains nothing — which is exactly how it should be.

FAQ

Does enabling the Cloudflare proxy alone hide my origin?

It hides the IP from your current DNS records, but it does not remove historical DNS data, certificate-scan exposure, or unproxied records like mail. Proxying is necessary but not sufficient — you also need the firewall allowlist so the origin refuses non- Cloudflare traffic.

I'm on shared hosting and can't edit the firewall. Am I out of luck?

No. Set SSL to Full (Strict), proxy every record you can, move email off the web origin, and ask your host to allowlist Cloudflare IPs at the server level — many cPanel providers will do this on request. These steps dramatically reduce your exposure even without root access.

How often do Cloudflare's IP ranges change?

Infrequently, but they do change. Never hardcode them once and forget. Pull the current list from cloudflare.com/ips on a schedule (a monthly cron job works well) so a future range addition does not silently start getting blocked, or worse, leave a gap.

Is Authenticated Origin Pulls better than IP allowlisting?

They solve slightly different problems. IP allowlisting blocks anyone not coming from a Cloudflare IP. Authenticated Origin Pulls (mTLS) cryptographically proves the request genuinely came from your Cloudflare account, which defends against the rare case of abuse from within Cloudflare's shared ranges. For most sites, the firewall allowlist is the essential baseline; mTLS is the stronger upgrade when your host supports it.