Configuring Domain DNS with Cloudflare

A Comprehensive Guide for Ubuntu Server Setup

Introduction

In this guide, we'll explore how to point a domain name to your Ubuntu server using Cloudflare's DNS services. This is a critical step in making your server accessible via a custom domain name. Whether you're purchasing a new domain or using an existing one, this process will ensure your domain correctly routes traffic to your server.

💡 Pro Tip: For this course, consider purchasing an affordable domain name with one of the new top-level domains (TLDs) available for as low as $0.99 per year. This allows you to experiment without significant investment.

Why Choose Cloudflare for DNS?

While you can use any domain registrar's DNS services, Cloudflare offers significant advantages that make it the preferred choice for professional deployments:

Cloudflare Advantages

⚡ Lightning-Fast Speed
🔒 Enhanced Security
🚀 Rapid Propagation
💰 Free Tier Available

Cloudflare's global network ensures your DNS queries are resolved quickly from anywhere in the world, while providing DDoS protection and other security features that typical registrar DNS services cannot match.

Getting Started with Cloudflare

Step-by-Step Setup Process

  1. Sign up for a free Cloudflare account at cloudflare.com
  2. Add your domain to Cloudflare using the guided wizard
  3. Cloudflare will scan your existing DNS records automatically
  4. Cloudflare will provide you with two nameserver addresses
  5. Log in to your domain registrar's control panel
  6. Update the nameservers to those provided by Cloudflare
  7. Wait for DNS propagation (typically 24-48 hours, but often much faster with Cloudflare)

Domain to Server Connection Flow

Domain Registrar
Cloudflare Nameservers
DNS Records
Your Ubuntu Server

Understanding DNS Record Types

For a basic WordPress setup on Ubuntu Server, you need to configure two essential DNS record types:

A Record (Address Record)

An A record maps your domain name directly to your server's IP address. This is the primary record that tells the internet where your server is located.

A Record Example:

Field Value Description
Type A Indicates this is an A record
Name @ Represents your root domain (e.g., example.com)
Content 192.0.2.1 Your server's IPv4 address
TTL Auto Time to Live (how long the record is cached)
Proxy Status DNS only Direct connection without Cloudflare proxy

CNAME Record (Canonical Name Record)

A CNAME record creates an alias that points to your domain name. This is commonly used for the "www" subdomain, ensuring that both "example.com" and "www.example.com" point to the same location.

CNAME Record Example:

Field Value Description
Type CNAME Indicates this is a CNAME record
Name www The subdomain alias
Target example.com Points to your root domain (not an IP address)
TTL Auto Time to Live
Proxy Status DNS only Direct connection without Cloudflare proxy
⚠️ Important: Never use an A record for the "www" subdomain. The "www" prefix is an alias and should always use a CNAME record pointing to your domain name, not directly to an IP address. This ensures consistency and easier management if your server IP changes.

Visual DNS Record Configuration

Required DNS Records

A Record

Type: A
Name: @ (or your domain)
Content: 192.0.2.1 (your server IP)
Proxy: DNS only ☁️

CNAME Record

Type: CNAME
Name: www
Target: example.com
Proxy: DNS only ☁️

Configuring DNS Records in Cloudflare

Practical Implementation Steps

  1. Access Cloudflare Dashboard
    Log in to your Cloudflare account and select your domain from the dashboard
  2. Navigate to DNS Settings
    Click on "DNS" from the left-hand menu to access DNS record management
  3. Remove Default Records
    Delete any existing DNS records that were automatically imported from your previous DNS provider. This ensures a clean slate and prevents conflicts
  4. Add A Record
    Click "Add Record", select type "A", enter "@" or your domain name, input your server's IP address, and set proxy status to "DNS only"
  5. Add CNAME Record
    Click "Add Record" again, select type "CNAME", enter "www" as the name, enter your domain name as the target, and set proxy status to "DNS only"
  6. Verify Configuration
    Double-check that both records show "DNS only" status (gray cloud icon, not orange)
✅ Configuration Complete: At this stage, you have successfully configured the essential DNS records. Your domain should now point to your Ubuntu server.

Understanding Proxy Status

DNS Only vs Proxied

Status Icon Behavior Use Case
DNS Only ☁️ (Gray Cloud) Traffic goes directly to your server Initial setup, SSL configuration
Proxied ☁️ (Orange Cloud) Traffic routes through Cloudflare After proper configuration for security & performance
⚠️ Critical Note: During initial setup, you must set the proxy status to "DNS only". Cloudflare's proxy features require proper configuration of your web server, SSL certificates, and security settings. We will enable the proxy later in the course after completing the necessary server configuration.

Why Start with DNS Only?

Starting with "DNS only" mode allows you to:

Real-World Example: expert-wp.help

Case Study Configuration

For the domain expert-wp.help, the DNS configuration would look like this:

Step 1: Select Domain in Cloudflare

Domain: expert-wp.help Status: Active Nameservers: Using Cloudflare nameservers

Step 2: Navigate to DNS Management

Click "DNS" from the left sidebar menu

Step 3: Remove Existing Records

Delete all auto-imported records from the previous DNS provider

Step 4: Add A Record

Field Value
Type A
Name expert-wp.help (or @)
IPv4 Address 203.0.113.42 (example - use your actual server IP)
Proxy Status DNS only (gray cloud)

Step 5: Add CNAME Record

Field Value
Type CNAME
Name www
Target expert-wp.help
Proxy Status DNS only (gray cloud)

Verification and Testing

How to Verify Your DNS Configuration

After configuring your DNS records, you can verify they're working correctly using various methods:

Command Line Testing (Linux/Mac/Windows):
# Check A record nslookup example.com # Check CNAME record nslookup www.example.com # Detailed DNS query dig example.com dig www.example.com

Expected Results

For A Record Query:

Server: 1.1.1.1 Address: 1.1.1.1#53 Name: example.com Address: 192.0.2.1

For CNAME Record Query:

Server: 1.1.1.1 Address: 1.1.1.1#53 www.example.com canonical name = example.com Name: example.com Address: 192.0.2.1

Common Mistakes to Avoid

❌ Common Configuration Errors

  • Using A record for www: Always use CNAME for www subdomain
  • Enabling proxy too early: Keep DNS only status until server is fully configured
  • Incorrect IP address: Double-check your server's IP from your hosting provider
  • Not removing old records: Delete conflicting records from previous DNS provider
  • Typos in domain names: Verify exact spelling, including TLD

Next Steps: Server Stack Installation

Once your DNS is properly configured and propagated, the next phase involves setting up the server software stack that will host and serve your WordPress sites. This includes:

Ubuntu Server Stack Components

Nginx
Web Server
+
MariaDB
Database
+
PHP 8.3
Scripting Language
=
LEMP Stack
Complete Solution

What Each Component Does

Component Role Purpose
Nginx Web Server Receives HTTP requests and serves web pages to visitors
MariaDB Database Management System Stores WordPress content, settings, and user data
PHP 8.3 Server-Side Scripting Language Processes WordPress code and generates dynamic content
🎯 Ready to Proceed: With your domain properly pointing to your server via Cloudflare DNS, you're now prepared to install the hosting stack that will power your WordPress sites. The combination of Nginx, MariaDB, and PHP 8.3 will provide a robust, high-performance environment for your web applications.

Summary Checklist

✓ Complete Configuration Checklist

  1. Domain registered with your preferred registrar
  2. Cloudflare account created (free tier is sufficient)
  3. Domain added to Cloudflare
  4. Nameservers updated at domain registrar to Cloudflare's nameservers
  5. All old DNS records removed from Cloudflare
  6. A record created pointing to server IP address
  7. CNAME record created for www subdomain
  8. Both records set to "DNS only" proxy status
  9. DNS propagation verified using nslookup or dig
  10. Ready to proceed with LEMP stack installation

Conclusion

Proper DNS configuration is the foundation of a successful web hosting setup. By using Cloudflare's DNS services and following the correct procedures for creating A and CNAME records, you've established a reliable connection between your domain name and Ubuntu server. The "DNS only" proxy status ensures that you can complete the necessary server configuration without interference, and you'll be able to enable Cloudflare's advanced security and performance features later once everything is properly set up.

Remember that DNS changes can take time to propagate across the internet, though Cloudflare's network typically ensures much faster propagation than traditional DNS providers. With your DNS properly configured, you're now ready to move forward with installing Nginx, MariaDB, and PHP 8.3 to create a complete hosting environment for WordPress.