Configuring Cloudflare as a DNS Provider for your Site

Configuring Cloudflare as a DNS Provider for your Site
Photo by Timothy Eberly / Unsplash

With the advent of several different hosting providers, domain registrars, and content management systems (CMS), there can be a sense of information overload on what the best practice configurations are. I aim to provide one of the many possible configurations for pointing your newly-purchased or soon-to-be purchased domain name to your new shop, portfolio, or blog.

What is DNS?

The domain name system's (DNS) primary purpose is to provide a mapping of alphabetical names to IP addresses over the internet. A hierarchy of name servers, from low level, local servers, all the way to the top level domain (TLD) servers (.com, .net, etc).

There are a few different types of DNS servers involved in resolving an address and loading a webpage:

  • DNS Recursor - Recursors are often the first stop in the DNS request chain. The recursor's primary purpose is to receive DNS requests from client devices and making the next request to find the authoritative nameserver.
  • Root Server - This is the top level of the system. It consists of 13 IP addresses maintained by the Internet Corporation for Assigned Names and Numbers (ICANN). These servers are primarily a reference to more specific name locations.
  • TLD Nameserver - As stated above, the TLD servers maintain information for all domain names with the same domain extension, such as .com, .net, .org, and .gov.
  • Authoritative Nameserver - This is the server that has direct access to the record requested by the end user, and will provide the authoritative answer of which IP address is mapped to the domain requested.


Overall, DNS can be a very complex topic the more you dive into it, and I still find its inner workings to be 'space magic' at times. For an ELI5 version, check out How DNS works.

Domain Names

ICANN authorizes companies to act as domain registrars, which are organizations you can use to purchase and register a domain name to you or your business. The benefit here is that it isn't necessarily important *where* you buy your domain, because you can always transfer to another registrar in the future.


A small but popular list of registrars you can use to purchase a domain name:

  1. GoDaddy
  2. NameCheap
  3. Google Domains
  4. Cloudflare

The process is relatively straightforward -- you search for the domain name you desire at the TLD you desire, and you pay the registration fee, typically for a year at a time. Depending on the name and TLD, the prices can range from a couple bucks to thousands of dollars.

Another detail to pay attention to are the ancillary services that the domain registrar may provide with the domain registration. For example, Namecheap provides domain privacy (to prevent personal information posted in DNS records), a premium DNS/DDOS solution, SSL certificates, and other services. I will be using Namecheap for the purposes of this walkthrough.

Why Cloudflare?

Cloudflare provides several services at its free tier that are paid offerings from many competitors:

  • DDoS mitigation
  • DNS Proxy
  • Content Delivery Network (CDN)
  • SSL Certificate

Cloudflare also provides several other paid offerings that are outside the scope of this particular subject, but feel free to peruse those here

Creating an Account

Creating an account on Cloudflare is very straightforward -- enter an email and password, confirm the email, and you're ready to go.

The first step is to 'add a website' in your Cloudflare dashboard. Enter the domain name that you purchased and then you will be prompted to choose a plan, which gives a quick overview of features.


Adding DNS Records

After selecting the plan, review the DNS records and add the appropriate A record. A records are those that map a domain name to an IPv4 address. To complete this step, have the public IPv4 address of your web server ready. Add the entry as such:


  • Click "Add Record"
  • Type A
  • Name: @
  • IPv4 address: address of web server
  • Proxy status checked

If you do not have the web server and/or domain information, it is okay to bypass it and return to it in the portal.

If you traverse to the DNS section of the Cloudflare portal, you will be presented with all of the DNS options necessary to get your site to resolve using Cloudflare DNS servers. Recommendations are provided at the top of the DNS page to help get you started as well. They will look like this:


Of those steps, the crucial one is to add a root record so that the root domain will resolve. You can also add a CNAME, or canonical name record, for the 'www' subdomain so that your site can be accessed at

After adding those records, the DNS Management section of the portal should reflect similar to this:


Changing the nameservers at the registrar

The next step is changing the nameservers of the domain so that they actually use Cloudflare, and not the standard nameservers that are provided by the domain registrar. After the DNS Management section of the DNS portal, the Cloudflare Nameservers section will provide you with the required entries needed at the domain registrar end:


If you are using Namecheap as a registrar, the settings for your domain should lead you to this page:


Change the Nameservers selection to Custom DNS, and enter the nameservers provided by Cloudflare:


You may have noticed that domain ownership needs to be verified prior to DNS functioning as intended. By adding those Cloudflare nameservers, you were verifying your ownership of the domain at the registrar, because generally the domain owner will be the only one able to change those settings.

It can take up to 24 hours as records propagate through the network, but you can check if the nameservers have been verified yet by going to the Overview portion of the portal and clicking "Check nameservers":


Periodically check back in until domain verification is done, and you should be able to contact your site at your purchased domain!

Closing Thoughts

I wanted to write this article as a supplement to my first article, "Hosting a Ghost Blog on DigitalOcean". This information will hopefully provide a near-complete guide on how to purchase a domain, set up a virtual machine, and host your new blog site.