Hey! Listen! This post is part of a series on the Ubiquiti EdgeRouter Lite. Check them all out!
|2019-02-03||EdgeRouter CNAME records|
|2017-10-03||Dyn DDNS on EdgeRouter|
|2017-04-25||DuckDNS on EdgeRouter|
|2017-01-08||Ubiquiti EdgeRouter serial console settings|
|2016-11-29||Ubiquiti UniFi controller setup on Raspberry Pi 3|
|2016-08-30||EdgeRouter Lite Dnsmasq setup|
|2016-06-13||EdgeRouter Lite software upgrade|
|2016-05-12||EdgeRouter Lite OpenVPN setup|
|2016-04-29||Ubiquiti EdgeRouter Lite setup|
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 --> 126.96.36.199 example.com --> 188.8.131.52
However, with a CNAME record, you can do this:
www.example.com --> example.com <-- This is the CNAME record example.com --> 184.108.40.206
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!