Understanding DNS for Self-Hosting: A Complete Guide
DNS turns domain names into IP addresses. Understanding DNS is essential for self-hosting — misconfigured DNS means nobody can reach your apps.
How DNS Works
When someone types yourapp.example.com:
1. Browser asks DNS resolver: what's the IP for yourapp.example.com?
2. Resolver checks cache. If not cached, asks the root nameservers
3. Root says: ask the .com nameservers
4. .com says: ask example.com's nameservers
5. example.com's nameservers return the IP address
6. Browser connects to the IP address
This happens in milliseconds, thousands of times a day.
DNS Record Types
A Record
Maps a domain to an IPv4 address.
example.com → 203.0.113.50
AAAA Record
Maps a domain to an IPv6 address.
example.com → 2001:db8::1
CNAME Record
Alias from one domain to another.
www.example.com → example.com
Important: CNAMEs cannot exist at the zone apex (example.com itself).
MX Record
Mail server for the domain.
example.com → mail.example.com (priority 10)
TXT Record
Arbitrary text. Used for email auth (SPF, DKIM, DMARC), domain verification, and more.
NS Record
Nameservers for the domain. Set at your registrar.
Common Self-Hosting DNS Setup
Single Server, Multiple Apps
Point all subdomains to the same IP. The reverse proxy routes by hostname.
app1.example.com → A → 203.0.113.50
app2.example.com → A → 203.0.113.50
app3.example.com → A → 203.0.113.50
Caddy or Nginx on the server reads the hostname and forwards to the correct container.
Wildcard DNS
Instead of individual records:
*.example.com → A → 203.0.113.50
Any subdomain resolves to your server. The reverse proxy handles routing.
TTL (Time to Live)
TTL tells resolvers how long to cache the record.
Before migrating servers: lower TTL to 300 seconds 24 hours in advance. After migration, raise it back.
Cloudflare as DNS
Cloudflare offers free DNS hosting with:
For self-hosting, Cloudflare DNS is the recommended choice. Free, fast, and adds security.