#Geo-based DNS routing

1 messages · Page 1 of 1 (latest)

delicate elm
#

I have a subdomain:

site.example.com

Is there a way to route traffic based on the client’s location?

For example:

  • If the client IP is from the US, route them to 127.0.0.1
  • Otherwise, route them to 127.0.0.2
devout pelicanBOT
#
Support AI

You can use Cloudflare's IP geolocation feature to route traffic based on the client's location.

First, you need to enable IP geolocation in the Cloudflare dashboard. To do this, go to the Network tab and toggle the IP Geolocation switch to On. Alternatively, you can enable it via the API by sending a PATCH request with ip_geolocation as the setting name in the URI path and the value parameter set to "on".

Once IP geolocation is enabled, you can use the CF-IPCountry header to determine the client's country. You can then use this information to route traffic to different origins based on the client's location.

However, to achieve the specific routing behavior you described, you would need to use Cloudflare's Load Balancing feature with Geo Steering. You can create a steering policy that routes traffic to different origins based on the client's geolocation.

Here's an example of how you can create a Geo Steering policy:

  1. Go to the Traffic tab and click on Load Balancing.
  2. Click on Create a Load Balancer and select Geo Steering as the steering policy.
  3. Configure the policy to route traffic to 127.0.0.1 for clients from the US and to 127.0.0.2 for clients from other countries.

Please note that you need to have the Load Balancing feature enabled on your Cloudflare account to use Geo Steering.

For more information on IP geolocation, please refer to the Cloudflare documentation: https://developers.cloudflare.com/network/ip-geolocation/

For more information on Geo Steering, please refer to the Cloudflare documentation: https://developers.cloudflare.com/load-balancing/understand-basics/traffic-steering/steering-policies/geo-steering/