What is the difference between an A record and a CNAME, and when do you use each?
BeginnerScenarioDNS & Service Discovery
Answer
Situation read → An A record maps a name to an IP; a CNAME maps a name to another name.
What I'd do →
- Use A (or AAAA) when you control a fixed IP, for example
app.example.com A 203.0.113.10 - Use CNAME when the target is a name owned by someone else, for example
www CNAME myapp.herokuapp.comor an ALB DNS name - Verify with
dig app.example.comanddig +short CNAME www.example.com - Never put other record types next to a CNAME on the same name
Why → A CNAME lets the provider change IPs without you touching DNS.
Interview tip → Mention that a CNAME adds a resolution hop, so it costs one extra lookup on cold cache.
More on DNS & Service Discovery
A customer types www.example.com in a browser. Walk through how DNS resolves it.BeginnerWhy can't you put a CNAME at the zone apex, and what do you use instead?BeginnerYou are moving a site to a new server. What do you do with DNS to make the cutover smooth?BeginnerHow do you find which nameservers are authoritative for a domain and query them directly?BeginnerWhat DNS records do you set up for company email?BeginnerWhen do you use /etc/hosts and when DNS?Beginner