Gibdos Talks FOSS

A Beginners Guide To Selfhosting Part 4

In Part 4 of our Beginners Guide, we will go through the DNS (Dynamic Name Server) setup for our VPS. DNS is like the phonebook of the internet. Translating your (Sub-)Domains (www.yourDomain.com) into IP adresses (XXX.XXX.XXX.XXX).

DNS Records

A DNS record is what links your domains to your IP adress. Here's a quick overview of the most common types of DNS records you might come across.

For our first little selfhosting project, we will rely entirely on A records.

Our first A record

The first A record you will need to add to your DNS records is your domain. It will tell the internet, that yourdomain.com can be found at XXX.XXX.XXX.XXX and will connect to your running Caddy container on port 80 (http) / 443 (https).

If you followed Part 3 of my guide, your Caddyfile has the optional entry

yourdomain.com {
  file_server
  encode zstd gzip
  import security_headers
}

As mentioned in part 3, this will serve any website you put into your /opt/docker/caddy/site folder. That directory is empty for the moment, so when you enter your domain into your browser you will get an error message. If you want to check whether your new record has been propagated on the internet, you can use this DNS Checker.

You can, of course, also connect your domain to a running docker service. Just change your Caddyfile accordingly.

yourdomain.com {
  reverse_proxy XXX.XXX.XXX.XXX:PORT {
   header_up X-Real-IP {remote_host}
  }
  encode zstd gzip
  import security_headers
}

Sub-Domains For Our Services

Depending on which services you want to use, you can start filling your DNS records with as many sub-domains as you want. A sub-domain is just another A record which points to your IPv4 adress (XXX.XXX.XXX.XXX).

Caddy will do the heavy lifting of taking the sub-domain and connecting it to whichever service you want.

Here is an example for Navidrome.

DNS Record

Recordname Record-Type Target Comment
music.yourdomain.com A XXX.XXX.XXX.XXX Navidrome

Caddyfile Entry

music.yourdomain.com {
  reverse_proxy XXX.XXX.XXX.XXX:3000 {
   header_up X-Real-IP {remote_host}
  }
  encode zstd gzip
  import security_headers
}

Navidrome compose.yml

services:
  navidrome:
    image: deluan/navidrome:latest
    user: 1000:1000
    ports:
      - "3000:4533"
    restart: unless-stopped
    volumes:
      - ".data:/data"
      - "./music/:/music:ro"

And that's basically all there is to DNS. At least for the time being. As mentioned in the Records section, it can get a little more complicated if you want to host a mail server, but that is outside the scope of this series.

In Part 5 of this series, we will go over all the services I run, with my compose.yml files.

A Beginners Guide To Selfhosting Part 5