Back to Blog
Domain Managment

How to Set Up DNS Records for Your Domain in Cloudflare

Setting up DNS records for your domain is one of those tasks that can feel daunting if you’re new to managing websites, but it’s a critical step to ensure your site is accessible, secure, and performing at its best.

9 min read
Share:
How to Set Up DNS Records for Your Domain in Cloudflare

Cloudflare, a leading platform for web performance and security, makes this process surprisingly straightforward with its intuitive interface and powerful tools. I’ve been through this process myself countless times, tweaking records for personal projects and client sites, and I’m here to walk you through it step-by-step. By the end of this guide, you’ll have your DNS records configured like a pro, whether you’re pointing your domain to a web host, setting up email services, or optimizing for speed and security.

Why Cloudflare for DNS Management?

Before we dive into the how-to, let’s talk about why Cloudflare is a great choice for managing your DNS. Cloudflare offers a robust, free-tier DNS management system that’s fast, secure, and reliable. Their global network of servers ensures low latency, and features like DDoS protection and automatic HTTPS rewrites add an extra layer of security without you lifting a finger. Plus, their dashboard is user-friendly, which is a lifesaver whether you’re a beginner or a seasoned developer. I’ve used other DNS providers in the past, but Cloudflare’s combination of simplicity and advanced features keeps me coming back.

Prerequisites

To follow along, you’ll need:

  • A domain name registered with a registrar (HahuCloud, Namecheap, GoDaddy, or Google Domains).

  • A Cloudflare account (free tier works fine for most cases).

  • Access to your domain registrar’s control panel to update nameservers.

  • A basic understanding of what you want your domain to do (e.g., point to a website, handle email, etc.).

If you don’t have a Cloudflare account yet, head to cloudflare.com, sign up, and add your domain to their system. Cloudflare will guide you through changing your domain’s nameservers to point to their servers—this is the first step to managing DNS through Cloudflare. It usually takes a few minutes, though nameserver changes can take up to 24 hours to propagate.

Step 1: Log In and Access the DNS Dashboard

Once your domain is added to Cloudflare and the nameservers are updated, log in to your Cloudflare account. From the dashboard, select your domain from the list at the top. Then, click on the DNS tab in the left-hand menu. This is where the magic happens. The DNS dashboard is where you’ll add, edit, or delete DNS records to control how your domain behaves.

You’ll see a table listing any existing DNS records. If you’ve just added your domain, Cloudflare may have automatically imported some records from your registrar or previous DNS provider. Take a moment to review these to avoid duplicates or conflicts.

Step 2: Understand Common DNS Record Types

Before adding records, it’s helpful to know the most common DNS record types and what they do. Here’s a quick rundown based on my experience working with domains:

  • A (Address) Record: Points your domain or subdomain to an IPv4 address (e.g., 192.0.2.1). This is what connects your domain to your web server.

  • AAAA (IPv6 Address) Record: Same as an A record but for IPv6 addresses (e.g., 2001:0db8::1).

  • CNAME (Canonical Name) Record: Aliases one domain or subdomain to another. For example, you might use a CNAME to point www.yourdomain.com to yourdomain.com.

  • MX (Mail Exchange) Record: Directs email to your mail server. You’ll need this if you’re using a service like Google Workspace or Zoho Mail.

  • TXT Record: Holds text data, often used for verification (e.g., Google Site Verification) or security protocols like SPF, DKIM, or DMARC.

  • SRV Record: Specifies a server for a specific service, like VoIP or instant messaging (less common for most users).

  • NS (Nameserver) Record: Indicates the nameservers for your domain. Cloudflare manages these automatically, so you rarely need to touch them.

Each record type serves a specific purpose, and you’ll likely only need a few depending on your setup. For a typical website with email, you might configure A, CNAME, MX, and TXT records.

Step 3: Add an A Record for Your Root Domain

Let’s start with the most common setup: pointing your root domain (yourdomain.com) to a web server. You’ll need the IPv4 address of your web server, which you can get from your hosting provider (e.g., SiteGround, DigitalOcean, or AWS).

  1. In the DNS dashboard, click Add Record.

  2. Set the Type to A.

  3. In the Name field, enter @ (this represents your root domain, like yourdomain.com).

  4. In the IPv4 address field, paste the IP address provided by your host.

  5. Set the TTL (Time to Live) to Auto unless you have a specific reason to change it. This controls how long DNS resolvers cache the record.

  6. Toggle the Proxy status to Proxied (orange cloud icon) if you want Cloudflare’s performance and security features, like caching and DDoS protection. Choose DNS Only (gray cloud icon) if you want to bypass Cloudflare’s proxy and point directly to your server.

  7. Click Save.

A quick tip from my own experience: If you’re unsure whether to use Proxied or DNS Only, start with Proxied. It’s easier to troubleshoot issues with Cloudflare’s optimizations enabled, and you can always switch to DNS Only later if needed.

Step 4: Set Up a CNAME for the “www” Subdomain

Most websites allow access via both yourdomain.com and www.yourdomain.com. To make this work, you’ll typically add a CNAME record for the www subdomain.

  1. Click Add Record.

  2. Set the Type to CNAME.

  3. In the Name field, enter www.

  4. In the Target field, enter @ (this aliases www.yourdomain.com to yourdomain.com).

  5. Set TTL to Auto.

  6. Set Proxy status to Proxied for consistency with your A record.

  7. Click Save.

This setup ensures that visitors to www.yourdomain.com are redirected to yourdomain.com (or vice versa, depending on your server configuration). Some hosts, like Netlify or Vercel, may require a CNAME to point to a specific hostname (e.g., your-site.netlify.app). In that case, use their provided hostname in the Target field instead of @.

Step 5: Configure MX Records for Email

If you’re using an email service like Google Workspace, Microsoft 365, or Zoho Mail, you’ll need to set up MX records to route emails correctly. Your email provider will give you a list of MX server addresses and their priority levels.

For example, let’s say you’re using Google Workspace:

  1. Click Add Record.

  2. Set the Type to MX.

  3. In the Name field, enter @ (for emails to yourdomain.com).

  4. In the Mail server field, enter the first MX server address (e.g., aspmx.l.google.com).

  5. Set the Priority to the value provided by Google (e.g., 1).

  6. Set TTL to Auto.

  7. Click Save.

  8. Repeat for any additional MX servers (Google typically provides five, with priorities like 5, 10, etc.).

One mistake I made early on was forgetting to delete old MX records from a previous email provider, which caused email delivery issues. Double-check your DNS dashboard and remove any outdated MX records to avoid conflicts.

Step 6: Add TXT Records for Verification and Security

TXT records are often used for domain verification or email security. For example, Google Workspace might ask you to add a TXT record to verify ownership of your domain. Similarly, setting up SPF, DKIM, and DMARC records helps prevent email spoofing and improves deliverability.

Adding a Verification TXT Record

  1. Click Add Record.

  2. Set the Type to TXT.

  3. In the Name field, enter @ (or a specific subdomain if instructed).

  4. In the Content field, paste the verification string provided by your service.

  5. Set TTL to Auto.

  6. Click Save.

Setting Up SPF, DKIM, and DMARC

  • SPF Record: Identifies which mail servers are allowed to send emails on behalf of your domain. Example: v=spf1 include:_spf.google.com ~all.

  • DKIM Record: Provides a cryptographic signature to verify email authenticity. Your email provider will give you a specific TXT record to add.

  • DMARC Record: Specifies how receiving servers should handle emails that fail SPF or DKIM checks. Example: v=DMARC1; p=none; rua=mailto:[email protected];.

Add each as a TXT record, following the same steps above. Be precise with the Content field, as even a single typo can break things. I learned this the hard way when a misplaced semicolon in an SPF record caused emails to bounce for a client.

Step 7: Test Your DNS Records

Once your records are added, it’s time to verify everything works. DNS changes can take anywhere from a few minutes to 24 hours to propagate, depending on your TTL settings and the global DNS network.

  • Check A and CNAME Records: Open a browser and visit yourdomain.com and www.yourdomain.com. If they load your website, you’re on the right track.

  • Verify MX Records: Use a tool like MXToolbox to check your MX records and ensure they point to the correct mail servers.

  • Test TXT Records: For verification records, follow your provider’s instructions to confirm ownership. For SPF/DKIM/DMARC, tools like DMARC Analyzer can help validate your setup.

  • Monitor Propagation: Use DNSChecker to see if your records have propagated globally.

If something isn’t working, double-check for typos, conflicting records, or incorrect proxy settings. Cloudflare’s DNS Only mode can help isolate issues by bypassing their proxy.

Step 8: Optimize with Cloudflare Features

With your DNS records set up, take advantage of Cloudflare’s additional features to boost performance and security:

  • Enable HTTPS: Go to the SSL/TLS tab and set it to Full or Full (strict) to ensure secure connections.

  • Turn on Auto Minify: In the Speed tab, enable Auto Minify to reduce the size of your HTML, CSS, and JavaScript files.

  • Set Up Page Rules: Use the Rules tab to create custom redirects (e.g., force www to non-www) or cache specific pages.

  • Activate Security Features: In the Security tab, enable DDoS protection and configure the Web Application Firewall (WAF) for added safety.

One tweak I always make is setting a Page Rule to cache static assets aggressively—it’s a simple way to speed up load times without touching your server.

Common Pitfalls to Avoid

Over the years, I’ve hit a few snags that are worth watching out for:

  • Duplicate Records: Adding a record that already exists can cause conflicts. Always review your DNS table before adding new entries.

  • Incorrect Proxy Settings: Using Proxied when your server expects DNS Only (or vice versa) can break things. Check your host’s documentation.

  • Propagation Delays: If your site or email isn’t working right away, give it time. Patience is key with DNS.

  • Forgetting Subdomains: If you’re hosting a blog at blog.yourdomain.com or a shop at shop.yourdomain.com, don’t forget to add A or CNAME records for those subdomains.

Final Thoughts

Setting up DNS records in Cloudflare is a straightforward process once you understand the basics. By following these steps, you can point your domain to your web server, configure email, and add security features with confidence. Cloudflare’s tools make it easy to manage everything in one place, and their free tier is more than enough for most small to medium-sized websites. I’ve seen firsthand how a well-configured DNS setup can improve site speed, reliability, and user trust—so take the time to get it right.

If you run into issues, Cloudflare’s support community and documentation are excellent resources. And if you’re ever stuck, tools like MXToolbox or DNSChecker can help pinpoint the problem. Now go forth and make your domain shine!

Y

Written by

Yared