Pointing Domain to Ubuntu Server Using Cloudflare and DNS

Summary:
Guide to configuring DNS records for your Ubuntu server.


Configuring your domain to point to an Ubuntu server is a fundamental skill for deploying websites and applications. By leveraging Cloudflare's DNS management, you not only direct traffic to your server but also gain benefits such as improved security and global CDN performance. This guide will walk you step-by-step through the process of linking your domain to your Ubuntu server using Cloudflare's DNS system.


Table of Contents

  1. Prerequisites
  2. Step 1: Prepare Your Ubuntu Server
  3. Step 2: Get Your Server IP Address
  4. Step 3: Add Your Domain to Cloudflare
  5. Step 4: Update Cloudflare DNS Records
  6. Step 5: Update Domain Registrar Nameservers
  7. Step 6: Test DNS Propagation
  8. Step 7: Secure Your Site with SSL
  9. Troubleshooting
  10. Conclusion

Prerequisites

Before starting, ensure you have:

  • A registered domain name.
  • An Ubuntu server with a public IP address (VPS, Cloud, or dedicated).
  • Cloudflare account (free or paid).
  • Access to your domain registrar.

Step 1: Prepare Your Ubuntu Server

Make sure your Ubuntu server is up and running, secured, and ready to accept connections (e.g., web server like Nginx/Apache installed).

Optionally, open the necessary firewall ports:

sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw enable

Step 2: Get Your Server IP Address

Find your server's public IP address. From Ubuntu CLI, type:

curl ifconfig.me

or

ip addr

or check your provider dashboard.

Let’s assume your IP address is: 203.0.113.10


Step 3: Add Your Domain to Cloudflare

  1. Log in to Cloudflare.
  2. Click on "Add a Site".
  3. Enter your domain name (e.g., yourdomain.com).
  4. Cloudflare will scan current DNS records; review and confirm.
  5. Choose a Cloudflare plan (Free is sufficient for most users).

Step 4: Update Cloudflare DNS Records

You’ll now add or modify the DNS records to point to your Ubuntu server.

a) Main Website (A Record)

  • Type: A
  • Name: @ (represents your root domain, e.g., yourdomain.com)
  • IPv4 address: 203.0.113.10
  • Proxy status: Set to "Proxied" (orange cloud) to enable Cloudflare features, or "DNS only" for direct access.
  • TTL: Auto

b) Subdomains (optional)

  • Type: A
  • Name: www (for www.yourdomain.com)
  • IPv4 address: 203.0.113.10
  • Proxy status: Preferred as "Proxied".
  • TTL: Auto

c) Example

Type Name Content Proxy Status
A @ 203.0.113.10 Proxied
A www 203.0.113.10 Proxied

Tip: Delete any old A/AAAA records not associated with your current server.


Step 5: Update Domain Registrar Nameservers

Cloudflare will provide you with two nameservers (e.g., rita.ns.cloudflare.com, tom.ns.cloudflare.com).

  1. Go to your domain registrar's dashboard.
  2. Find Nameserver settings.
  3. Replace existing nameservers with the ones given by Cloudflare.
  4. Wait for DNS changes to propagate (usually within minutes to 24 hours).

Step 6: Test DNS Propagation

Check if your domain points to your server:

  • Online tools: dnschecker.org
  • Command line:
    nslookup yourdomain.com
    dig yourdomain.com
    

Expected result: Your Ubuntu server’s IP (e.g., 203.0.113.10) should be returned.


Step 7: Secure Your Site with SSL

Cloudflare provides free SSL for your domain.

a) In Cloudflare Dashboard

  1. Navigate to the "SSL/TLS" section.
  2. Set SSL mode to Full (recommended) if you have a certificate on your server, or Flexible otherwise (temporary).
  3. Consider installing a free Let’s Encrypt SSL certificate on your Ubuntu server for end-to-end encryption.

b) On Ubuntu (Let’s Encrypt Example)

sudo apt update
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Troubleshooting

  • DNS records not resolving: Double-check record values, clear local DNS cache, verify propagation using DNS tools.
  • ERR_SSL_VERSION_OR_CIPHER_MISMATCH: Ensure SSL mode in Cloudflare matches your server certificate.
  • Site not loading: Ensure your web server (Apache/Nginx) is running, firewalls allow traffic, and your server’s IP is correct in DNS.

Conclusion

Connecting your domain to an Ubuntu server using Cloudflare’s DNS services is straightforward and brings performance and security enhancements to your web projects. Whether you’re running a small blog or a business application, leveraging Cloudflare ensures your DNS is robust and future-proof. Don’t forget to maintain your server’s security, keep DNS records updated, and periodically review Cloudflare settings for optimal protection.


Need help?
If you have any questions or want to automate deployments, feel free to leave a comment below!