Back

My Cloudflare DNS Misadventure: How I Accidentally Sent My Domain Abroad

MasterMao

Hello everyone, this is MaoMaoyu.

The "Sweet Trap" of Vercel + Cloudflare

My website is hosted on Vercel, with Cloudflare managing domain resolution and CDN. Before the problem arose, I made a seemingly normal adjustment:

  1. Vercel Setup: In Vercel's Domains settings, I used the Redirects to feature to redirect domain A (maomaoyu.coffee) to domain B (top4ai.com).
  2. Cloudflare Setup: In Cloudflare, I configured the following DNS records:
    • A maomaoyu.coffee: 76.76.21.21 (Proxied)
    • CNAME www.maomaoyu.coffee: maomaoyu.coffee (Proxied) (After multiple tests, I suspect this is where the problem lies, intended to redirect www to @)

The Issue: My Domain Was "Exiled" Overseas

To my surprise, this simple configuration resulted in my domain B (top4ai.com) being resolved to seven or eight overseas IP addresses. This made my website completely inaccessible in China!

The Crux: I suspect a conflict between Cloudflare's "Proxied" setting and Vercel's redirection mechanism. Due to DNS caching, testing this bug is incredibly tedious.

My Attempts at Damage Control

To resolve this issue, I tried the following two methods:

1. (Ineffective) Cloudflare Redirect Rules

I first attempted to set up two 301 redirect rules in Cloudflare's Rules - Redirect Rules, redirecting both maomaoyu.coffee and www.maomaoyu.coffee to top4ai.com.

  • Rule Configuration:
    • Hostname Equals www.maomaoyu.coffee
    • Expression Preview: (http.host eq "www.maomaoyu.coffee")
    • URL Redirect:
      • Type: Dynamic
      • Expression: concat("https://top4ai.com", http.request.uri.path)
      • Status Code: 301
  • Result: After a few hours, the problem reappeared, and the domain was again resolved to overseas IPs. This method failed.

Conclusion: Setting up redirect rules directly in Cloudflare did not solve the problem.

2. (Effective) Adjusting Cloudflare and Vercel DNS Settings

After various unsuccessful attempts, I adjusted the DNS settings in both Cloudflare and Vercel:

  • Cloudflare Configuration:
    • A maomaoyu.coffee: 76.76.21.21 (Proxied)
    • CNAME www.maomaoyu.coffee: cname.vercel-dns.com (Proxied)
    • A top4ai.com: 76.76.21.21 (DNS only)
    • CNAME www.top4ai.com: cname.vercel-dns.com (DNS only)
  • Vercel Configuration:
    • Set up a 301 redirect in Vercel.

Result: After observing for a day, both the redirect and website access are now normal. However, I am completely afraid of enabling Cloudflare's "Proxied" for top4ai.com. As soon as I do, it gets assigned seven or eight overseas IPs.

Conclusion: By disabling Cloudflare proxy for top4ai.com and using Vercel for redirection, the issue was resolved.

Questions and Requests for Help

Why does enabling Cloudflare's "Proxied" for top4ai.com lead to it being resolved to overseas IPs? What is the underlying mechanism? I'm hoping someone can shed some light on this!

My Current Guesses:

  • Could there be a conflict between Cloudflare's proxy mechanism and Vercel's redirection mechanism?
  • Or could there be some unknown rules in Cloudflare's DNS resolution mechanism?

Additionally, I really need a good DNS testing tool because DNS caching makes testing very cumbersome!

If you've had similar experiences or have any insights into this issue, please share them in the comments!