Unit 14 ยท Hosting and Publishing a Web Site

14.2Introduction to DNS

DNS (Domain Name System) is the internet's phonebook. Computers find each other by IP address (like 203.0.113.25), but people remember names. DNS translates www.myshop.lk into an IP address.

How a lookup works

Your computerbrowser / OS cacheRecursive resolver(your ISP)Root serverknows the TLDs.lk TLD serverknows myshop.lk's NSAuthoritative NSns1.host.comWeb server203.0.113.251www.myshop.lk?2โ†’ ask .lk servers3โ†’ ask ns1.host.com4โ†’ 203.0.113.255IP (cached for TTL)6connect, request page
DNS lookup: the resolver asks the root, then the TLD, then the authoritative server for the IP address

Results are cached for the record's TTL (time to live, in seconds) so lookups stay fast.

Important DNS record types

RecordPurposeExample
AName to IPv4 address@ A 203.0.113.25
AAAAName to IPv6 address@ AAAA 2001:db8::1
CNAMEAlias to another namewww CNAME myshop.lk
MXMail servers for the domain (with priority)@ MX 10 mail.myshop.lk
TXTFree text: SPF, DKIM, DMARC, domain verification@ TXT v=spf1 include:_spf.host.com ~all
NSThe authoritative nameservers for the domain@ NS ns1.host.com

(@ means the bare domain, myshop.lk itself.)

Pointing a domain to your host: two ways

  1. Change nameservers at the registrar to the ones your host gives you (e.g. ns1.host.com, ns2.host.com). The host then manages all records.
  2. Keep nameservers at the registrar (or at a DNS provider such as Cloudflare) and add an A record with your host's IP address, and a CNAME for www.

Propagation: changes can take minutes to 48 hours to be visible everywhere, because of cached TTLs. Lower the TTL (e.g. 300) a day before planned changes.

Check DNS yourself

Terminal
nslookup myshop.lk
nslookup -type=MX myshop.lk
dig myshop.lk A
dig +short www.myshop.lk CNAME

Online tools: whatsmydns.net, mxtoolbox.com. Local testing trick: edit the hosts file to map a name to an IP on your own computer only.