August 10, 2018

Domains and Sub-domains for Home-Hosted Services

I like to host (most of) the web services I use for my daily routine at home. Recently, I started shipping services using Docker containers. To make these services available via a public IP address and to conveniently enable HTTPS, I decided to use nginx as a reverse proxy. So the dockerized service becomes available via something like https://mydomain.dyndnsservice.xy/servicename. At least this was the plan.

Unfortunately, I ran into the always same problem when I tried to coax a dockerized service to live happily in a “sub-folder” of my dynamic DNS domain. Many services like Gitlab or Wallabag are simply not built for this. The web is full with people asking for help and the answer is mostly: it is not supported, get yourself a sub-domain.

I had no idea how it can be achieved to host sub-domains on a server with a dynamic IP address. Dynamic DNS services typically only allow you to maintain and update the A record of your dynamic DNS domain (something like mydomain.dyndnsservice.xy). So there is no option how a NS record could be created which would direct a DNS resolver to the server. Additionally, you of cause would need a DNS server authoritative for the local sub-sub-domains subdomain.mydomain.dyndnsservice.xy.

As an alternative I started to use several dynamic DNS names that pointed to the same server. But I did not like this option too much. By accident I stumbled upon a feature of another dynamic DNS service I know. https://afraid.org (stupid name, but cool service) does not only work like your average dynamic DNS service but more like a full featured DNS service supporting many DNS record types. Additionally, afraid.org has neat dynamic DNS features.

So what I did was the following:

  1. you register a new domain mydomain.xy with some registrar. If you want a free domain (like the one I use for this blog) you could use one from https://www.freenom.com/.

  2. you tell afraid.org about the new domain mydomain.xy by selecting “Add A Domain into FreeDNS”. If you do not select “private domain” you allow other afraid.org users to register a sub-domain withing your domain. You maybe do not want that.

  3. you change the name servers of mydomain.xy (using the freenom.com site) and make them point to the ones suggested by afraid.org.

  4. you enable an update mechanism that updates the A record of mydomain.xy, which is now managed by afraid.org, so that it always points to the current IP of your server at Home. On the afraid.org site you find some snippets that are helpful like this small cron-based updater:

     4,9,14,19,24,29,34,39,44,49,54,59 * * * * sleep 40 ; wget -O - http://freedns.afraid.org/dynamic/update.php?secretsercretsecret >> /tmp/freedns.log 2>&1 &
    
  5. You server can now be reached via mydomain.xy. Neato. Now you can register subdomin.mydomain.xy using afraid.org. Do not create an A record but just point the new sub-domain's CNAME record mydomain.xy.

© holger 2015 - 2020 |