How to Configure Cloudflare DNS for a Faster Website and Better DDoS Protection

By Diq - Editor & Writer at The Tips Tricks Updated: Technology 5 min read 19 views
How to Configure Cloudflare DNS for a Faster Website and Better DDoS Protection
Illustration: How to Configure Cloudflare DNS for a Faster Website and Better DDoS Protection
Table of Contents
  1. Step 1: Register Your Domain and Check DNS Records
  2. Step 2: Change Nameservers at Your Registrar
  3. Step 3: Set Proxy Status Correctly
  4. Step 4: Configure SSL/TLS Correctly
  5. Step 5: Enable Anti-DDoS Protection and WAF
  6. Step 6: Optimize Speed with Caching and Compression
  7. Fatal Mistakes Beginners Often Make

Have you ever opened your own website and found pages responding slowly even though your internet connection is fine? Or suddenly the site goes down for no clear reason? Often the cause isn't a maxed-out server, but DNS records that are still exposed without a proxy layer. Your server's real IP address can be seen by anyone, making it vulnerable to floods of fake traffic. The result: legitimate visitors get slowed down too, and even the server's processor can run out of power just serving repeated requests for images and CSS.

Cloudflare acts as an intermediary (reverse proxy) that hides the real IP and distributes static assets from the server closest to the visitor. Integration doesn't require moving website files—you just point the nameservers. Here's a practical guide you can follow directly, plus common mistakes beginners often make.

Step 1: Register Your Domain and Check DNS Records

Create a Cloudflare account, click Add a Site, and enter your main domain name (without www). Cloudflare will scan your existing DNS records. Check them one by one: make sure the A record for the main domain, the CNAME for www, and the MX and TXT records for email match your old hosting settings exactly. If anything is missing, add it manually. A mistake at this stage can cause email to stop being delivered or subdomains to go dead.

Step 2: Change Nameservers at Your Registrar

Cloudflare gives you two nameserver addresses. Log in to your domain purchase panel, change the nameservers from the default to custom, and enter both addresses. Propagation usually takes a few minutes to 24 hours. To confirm it's pointing to Cloudflare, run the following command in your terminal:

nslookup -type=ns yourdomain.com

If the output shows Cloudflare nameservers (for example ns1.cloudflare.com), the process is complete.

Step 3: Set Proxy Status Correctly

In the DNS menu, each record has an orange cloud (proxied) or gray cloud (DNS only) toggle. Not all records should be proxied. Use the following table as a guide:

StatusHow It WorksAppropriate Records
Proxied (Orange Cloud)Traffic passes through Cloudflare, real IP is hidden, DDoS protection and CDN enabledA, AAAA, CNAME for the main website (@, www, web subdomains)
DNS Only (Gray Cloud)Traffic goes directly to the destination server without a proxyMX, TXT (SPF/DKIM), non-HTTP subdomains such as mail, ftp, SSH

Enabling the proxy on MX records will break email service. Conversely, leaving web records gray exposes your real IP.

Step 4: Configure SSL/TLS Correctly

Open the SSL/TLS > Overview menu. Many beginners choose Flexible mode even though their hosting already has SSL, resulting in an ERR_TOO_MANY_REDIRECTS error. If your server already has a valid certificate installed (Let's Encrypt or a Cloudflare Origin Certificate), choose Full (Strict). Then in Edge Certificates, enable Always Use HTTPS and Automatic HTTPS Rewrites so all HTTP access is redirected to HTTPS without mixed content.

Step 5: Enable Anti-DDoS Protection and WAF

Cloudflare automatically filters basic DDoS attacks, but you need to refine the application layer:

  • Bot Fight Mode: enable it under Security > Bots to hinder scraper bots and vulnerability scanners.
  • WAF Custom Rules: under Security > WAF > Custom rules, create rules to block or issue a Managed Challenge on requests to sensitive pages such as /wp-login.php or /xmlrpc.php.
  • Under Attack Mode: if your site is being flooded with abnormal traffic, turn on this switch. Visitors will pass a brief browser check, and bots are automatically filtered out.

Step 6: Optimize Speed with Caching and Compression

Go to Speed > Optimization and make sure Brotli is enabled so text files (HTML, CSS, JS) are compressed more efficiently. Under Caching > Configuration, set Browser Cache TTL to at least a few days (for example 4 days) for static assets. For assets that change frequently, use Purge Cache with Custom Purge mode on specific URLs only, so changes appear immediately without forcing the server to reload the entire site.

Field Note: Enabling the orange cloud doesn't guarantee your server IP is fully hidden if a subdomain like mail or cpanel is set to gray and points to the same IP. If you use a self-managed VPS, restrict ports 80 and 443 in your server firewall to Cloudflare's official IP ranges only. That way, attackers can't bypass protection even if they know the origin IP.

Fatal Mistakes Beginners Often Make

The following mistakes can keep your website slow or even make it inaccessible:

  • Enabling the proxy on email (MX) records — email stops working immediately. Make sure MX records are always gray.
  • Choosing Flexible SSL mode when hosting already uses HTTPS — causes a redirect loop. Use Full (Strict).
  • Forgetting to change nameservers at the registrar — even after registering with Cloudflare, traffic still won't pass through the proxy. Check with the nslookup command above.
  • Not excluding webhooks or payment bots from WAF rules — transactions can fail because they're treated as bots. Always monitor Security > Events regularly.

To make sure there are no conflicts between domain versions, also read the guide www vs non-www: which to choose for SEO. If you manage your own server, it's also important to understand how to force HTTPS via .htaccess as an additional layer.

Start today: check the proxy status in your Cloudflare DNS menu. Make sure only web records have the orange cloud, and immediately switch your SSL mode to Full (Strict) if you haven't already. After that, enable Bot Fight Mode and set Browser Cache TTL to at least 4 days. These small changes will be immediately noticeable in your site's speed and resilience against attacks.

Note: The settings above may vary slightly depending on your Cloudflare dashboard and hosting type. Back up your DNS configuration before changing nameservers or WAF rules, and test after making changes. For the latest list of official Cloudflare IPs, check the official Cloudflare documentation.

Share:
D
About the Author
Diq Editor & Writer at The Tips Tricks

IT practitioner and web developer. Writes practical, hands-on technology guides covering the web, software, everyday devices, and internet troubleshooting in clear, actionable steps.

About & Editorial →

Discussion (0)

No comments yet. Be the first to join the discussion.