How to configure DNS for a web application

· Category: Networking

Short answer

To point a domain to your web application, create an A record pointing your domain to your server's IP address, and a CNAME record for the www subdomain pointing to your main domain. For a deeper understanding of how DNS works, see how to configure DNS records.

Essential DNS records for a web app

Record type Purpose Example
A Maps domain to IPv4 address example.com → 203.0.113.50
AAAA Maps domain to IPv6 address example.com → 2001:db8::1
CNAME Alias from one domain to another www.example.com → example.com
MX Mail server for the domain example.com → mail.example.com
TXT Arbitrary text (SPF, verification) example.com → "v=spf1 include:_spf.google.com ~all"

Step-by-step setup

  1. Register your domain at a registrar (Namecheap, Cloudflare, GoDaddy)
  2. Point nameservers to your DNS provider (or use the registrar's)
  3. Create an A record: Host @, Value your-server-ip, TTL 3600
  4. Create a CNAME: Host www, Value example.com, TTL 3600
  5. Wait for propagation — usually 5 minutes to 48 hours depending on TTL

TTL considerations

  • Short TTL (300–600s): Use during migrations so changes propagate quickly
  • Long TTL (3600–86400s): Use for stable production to reduce DNS lookup load
  • Lower TTL before planned changes, raise it after

Tips

  • Always set up both example.com and www.example.com — users type both
  • Use CNAME for subdomains pointing to cloud services (e.g., app.example.com → myapp.herokuapp.com)
  • For understanding CIDR and IP addressing related to DNS, see how to calculate CIDR
  • If using Cloudflare as DNS proxy, it handles CDN and DDoS protection too — see how to choose a cloud provider