EdgeRouter CNAME records

Hey! Listen! This post is part of a series on the Ubiquiti EdgeRouter Lite. Check them all out!

DateURLPart
2019-06-28Migrating away from the Ubiquiti EdgeRouter Lite
  • Migrated to a Netgate SG-1100
  • 2019-02-03EdgeRouter CNAME records
  • Setup CNAME records
  • 2017-10-03Dyn DDNS on EdgeRouter
  • Setup DynDNS
  • 2017-04-25DuckDNS on EdgeRouter
  • Setup DuckDNS
  • 2017-01-08Ubiquiti EdgeRouter serial console settings
  • Serial console settings
  • 2016-11-29Ubiquiti UniFi controller setup on Raspberry Pi 3
  • Install UniFi Controller
  • 2016-08-30EdgeRouter Lite Dnsmasq setup
  • Setup dnsmasq
  • 2016-06-13EdgeRouter Lite software upgrade
  • Firmware upgrade
  • 2016-05-12EdgeRouter Lite OpenVPN setup
  • OpenVPN server setup
  • 2016-04-29Ubiquiti EdgeRouter Lite setup
  • Initial setup
  • Introduction

    What is a CNAME record?

    A canonical name (CNAME) record is a special type of DNS record that points one domain name to another.

    It’s easier to explain with an example. Let’s say you own the website example.com, and you want to setup both www.example.com and example.com to go to the same place application (e.g., WordPress). You could maintain two separate A records, like this:

    www.example.com --> 11.22.33.44
    example.com     --> 11.22.33.44

    However, with a CNAME record, you can do this:

    www.example.com --> example.com           <-- This is the CNAME record
    example.com     --> 11.22.33.44

    With this setup, if your server address changes, you only need to update one record (the record for example.com).

    CNAMEs as “shortcuts”

    The really cool part about CNAME records is that you can create DNS “shortcuts” with them.

    Time for another example. Let’s say you want to setup a backup server (with the hostname backup01) at your house and connect all your devices to it. This way, every device can backup to one central location.

    device01 --\
    device02 ---|--> backup01.localdomain
    device03 --/

    However, eventually, the server named backup01 will need to be replaced with backup02, and when that happens, you’ll need to reconfigure every device in your house to point to the new server. But, what if you could setup a DNS name between each device and the backup server? This record is the CNAME record.

    device01 --\
    device02 ---|--> storage.localdomain --> backup01.localdomain
    device03 --/

    With this setup, you can point every device to storage. Then, when backup01 eventually needs to be replaced with backup02, you can just update the CNAME record of storage. This is exactly what I’m using CNAME records for at home.

    Setting up CNAME records

    First, you’ll need to be using dnsmasq on your EdgeRouter instead of the default DHCP server (written by the ISC). If you don’t have dnsmasq running, I have a quick guide for that here, and Ubiquiti’s official guide is here.

    Next, you simply set your CNAME records with the command below. In this case, storage is the CNAME record, while backup01 is the actual server name.

    configure
    set service dns forwarding options cname=storage.localdomain,backup01.localdomain
    commit
    save

    Now, you can use the name storage on all your devices, and then update the CNAME record when you replace the server that’s behind the record.

     

    Hope this helps!

    Logan

    4 thoughts on “EdgeRouter CNAME records”

    1. Hi Logan.
      I have a bash script that I want to set up cname records so that google searches are forced to use forcesafesearch.google.com.
      e.g.
      host-record=forcesafesearch.google.com,216.239.38.120
      cname=www.google.com,forcesafesearch.google.com
      cname=google.com,forcesafesearch.google.com

      I’ll do this for all the google supported domains from https://www.google.com/supported_domains
      Is the above the correct format? I’ve saved the configuration file in the /etc/dnsmasq.d directory, is this the correct place?

      Cheers
      Dwayne

      • The EdgeRouter wipes out EVERYTHING except /config upon a firmware update, so if you’re putting the DNS entries into /etc/dnsmasq.d, they will be wiped out upon a firmware update (unless your script recreates the entries after an upgrade). You should put the entries into your /config/config.boot file.

        • Only just saqw your reply, thanks for your reply and letting me know what is preserved during the firmware update process. Losing scripts and debian packages with firmware updates is a bugbear of mine. So, so grateful for your comment.

          My script is in /config/scripts and it creates a file in /etc/dnsmasq.d/.

    2. Hi Logan managed to fix my issue.
      There was a stray host-record in /etc/dnsmasq.conf, once deleted my code ran correctly.

    Leave a Comment

    This site uses Akismet to reduce spam. Learn how your comment data is processed.