How To Hide Your Server's IP Address For Free With Cloudflare
Date: 2025-01-22 | cloudflare | create | webapps |
I build a lot of webapps. This means hosting those webapps and making them publicly available to the internet so people can use them.
While the internet is an amazing place it can also be a scary / mean one and if a mean side of the internet gets ahold of your server's IP Address they can do all sorts of mean things like DOS it or try to break in. Security by obscurity should never be relied on but sometimes it helps.
So here I'll explain a simple (and free!) way to hide your server's IP address using Cloudflare so you get a little bit more protection from the mean internet.
Solution Overview
Basically what we're going to do is:
- Point our url / domain to Cloudflare
- Tell Cloudflare to proxy traffic to our server
- [Optional] Configure Cloudflare to make SSl (https) work e2e
This will allow the end user to use the url to hit our webapp BUT they don't see our server's IP Address (they'll see Cloudflare's instead).
Point URL to Cloudflare
First we need to point our url to Cloudflare.
The best instructions are going to be from Cloudflare themselves so login and follow the Add Domain
instructions.
Generally this involves:
- Go to your domain registrar
- Set the nameservers to Cloudflare
This basically says "this domain and its configurations are controlled over there" (on Cloudflare).
Proxy traffic from Cloudflare to our server
Once we've configured our domain to be configured with Cloudflare, we need to configure it to proxy our server.
- Get the IP address of your server
- Create an A record in Cloudflare pointing your URL to your server ip address
- Make sure the Proxy status says
Proxied
(little orange cloud thing)
Now when the user hits our domain and gets sent to Cloudflare, Cloudflare will send back their IP adresses instead of your server's - effectively hiding it.
[Optional] Configure Cloudflare to fix SSL / HTTPS
Whenever I do this with a site that has https
set up on it, I always run into the same Cloudflare error. So this section is not strictly required (if your site works fine, skip it) but I always end up needing to do this so noting it down for posterity.
The issue seems to be some sort of mixup in https / ssl certificates between:
- User -> Cloudflare
- Cloudflare -> Server
This ends up returning some sort of error similar to "we can't create a secure connection" or something.
Example error: This site can’t provide a secure connection. ERR_SSL_VERSION_OR_CIPHER_MISMATCH
.
In like 99% of cases where I've had SSL / https issues with Cloudflare, changing the SSL / TLS encryption mode from Flexible to Full (Strict) has fixed it. I don't really know why but that's been my experience.
So if you're running into issues with this and you know your site works with ssl / https before doing the Cloudflare proxy I'd recommend trying to change this setting, waiting a few minutes for changes to propagate, and checking again.
To do this:
- Go to Cloudflare
- Select
SSL/TLS
from toolbar - Click
Configure
SSL / TLS encryption mode - Select
Full (Strict)
- Click
Save
Example: TTL Calculator
I just published my latest site TTL Calculator. It's running on a server (along with several other webapps) configured with Coolify.
- Server IP:
CENSORED
- Ping IP:
104.21.80.1
(not my server IP)
So this Cloudflare proxy seems to work p well.
Next
Cloudflare is an extra step of configuration but generally they provide a lot of benefits for little cost. So if you're on the fence it's worth trying out with a side project or two to get a feel for it.
If you liked this post you might also like:
Want more like this?
The best way to support my work is to like / comment / share for the algorithm and subscribe for future updates.