How to setup CNAME

Hi @py4mac. For the benefit of other users who may find this thread, let me cover two scenarios:

  1. You have an actual internet domain name (globally resolvable by root DNS servers) like, say “py4mac.com”, which was “bought” through a domain name registrar - a company like, say, GoDaddy.com.

  2. You have a “local” domain name that is not globally resolvable in the internet (like “openbalena.local”), and was not registered through any internet domain name registrar. Yet, you want your local network to be able to resolve names under that domain name, like “api.openbalena.local”.

The vast majority of users fall in the first category, so let me emphasise that it is not necessary to run your own DNS server (using BIND9 or otherwise) on your local network, even if you are running openBalena on a private on-premises network. Like @imrehg pointed out in his answer, by far the easiest and most reliable solution is to use the registrar’s web control panel (again, like GoDaddy’s) to register CNAME records. By the way, it’s OK to add private IP addresses to the public internet DNS; for example, it’s OK to use GoDaddy’s control panel to add a private IPv4 address like 192.168.50.50 to a public DNS record like, say, “api.py4mac.com”. Of course, a private IP address is only routable within its private network, so external machines won’t be able to reach it even if they are able to resolve the DNS name.

If you are in the second category, even then there may be simpler solutions to consider before trying BIND 9. Although the openBalena guide mentions CNAME records, ultimately what matters is that your local network is able to map hostnames (like {api | registry | vpn | s3}@mydomain.com) to the IP address of your openBalena server. To this end, some options are:

  • Configuring your WiFi router - some WiFi routers offer the feature of working as a forwarding DNS server, and allow mapping host names to IP addresses.

  • Using the /etc/hosts file on Linux or MacOS (under Windows, I think the file is C:\Windows\System32\Drivers\etc\hosts), adding lines similar to the ones below (replace 192.168.50.50 with the IP address of your server/laptop). Note that in this case, you’d have to configure every device separately.

192.168.50.50   s3.openbalena.local
192.168.50.50   api.openbalena.local
192.168.50.50   vpn.openbalena.local
192.168.50.50   registry.openbalena.local
  • Using dnsmasq, which is a simpler DNS server than BIND 9. Check the following page for some brief instructions, especially the section “Adding a custom domain”: https://wiki.archlinux.org/index.php/dnsmasq
    dnsmasq will look in the /etc/hosts file of the machine it is running on, so you would add lines similar to the ones above to that machine. But then you only need to edit the /etc/hosts file of that one machine, rather than every devices’.

  • Finally, using BIND 9. I believe the following Ubuntu guide covers some of your questions: https://help.ubuntu.com/community/BIND9ServerHowto
    After the header lines (SOA, NS, PTR), your db.openbalena.local file could contain the following lines (replace 192.168.50.50 with the IP address of your laptop):

laptop    IN    A      192.168.50.50
api       IN    CNAME  laptop
s3        IN    CNAME  laptop
registry  IN    CNAME  laptop
vpn       IN    CNAME  laptop

Regards,
Paulo