Using /cdn-cgi/trace


Can we call the /cdn-cgi/trace from device’s web browsers to get their public IP address and country code? Or are there any limitations? We plan to use that instead of commercial services like ipgeolocation[dot]io, maxmind or ipstack[dot]com since we need just public IP and ISO country code.

Thank you

This is not necessary. Cloudflare sends the client IP address in the request headers to your origin, and you can enable geolocation information in the request headers as well. See these two pages:



Thanks a lot, but I probably do not understand your suggestion. Let me ask once again: How it helps me that Cloudflare sends the client IP address in the HTTP request headers to the origin? The content downloaded by the web browser is cached on the CDN 99.9% times and origin is rarely used. I need to know the public IP address in the device’s web browser to work with that in the web app.

The only way I found other than using /cdn-cgi/trace is creating the custom HTTP response headers by using the “Transform Rules”


So you have purely client-side code where you want this information?

As far as I know, the content and format of /cdn-cgi/trace isn’t guaranteed and is meant for debugging only. So while it will work, I don’t think it’s the best plan. You can indeed use a Transform Rule to add this information to the response headers and then use your own URL, and I think that’s the better plan. Use ip.src and


Yed, indeed. This is purely client-side code, where I require it.

At the end we have decide to use the commercial solution for geolocation information (public IP and country ISO code) with the fallback to either /cdn-cgi/trace or Transform Rules.

Have a nice day

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.