DNS Records: One IP for Primary Domain and One IP for Multiple Subdomain

I'm using Cloudflare (no proxy) to manage DNS Records. I have two servers with IP:

  • 128.xxx.xxx.xxx
  • 174.xxx.xx.x

And these are the DNS Records that I have created:

Type Name Content
A example.com 128.xxx.xxx.xxx
CNAME sub1 example.com
CNAME sub2 example.com
CNAME sub3 example.com

Now, I want to point the main domain (example.com) to the new IP (174.xxx.xx.x), the subdomains (sub1, sub2, sub3) keep using 128.xxx.xxx.xxx.

I could of course change the DNS records for each subdomain to type A by pointing all subdomains to IP 128.xxx.xxx.xxx like this:

Type Name Content
A example.com 174.xxx.xx.x
A sub1.example.com 128.xxx.xxx.xxx
A sub2.example.com 128.xxx.xxx.xxx
A sub3.example.com 128.xxx.xxx.xxx

The problem is, I have a lot of subdomains and the number is growing, I don't want to manually write the IP for the subdomains, apart from many, I'm also worried that I will switch servers with different IP addresses later.

Is there any way to solve this problem?

I really appreciate any answer, thanks in advance.


Solution 1:

You could create an A record cname.example.com, with the 128.xxx.xxx.xxx IP address.

Then for each domain, you would have CNAME point to cname.example.com.