🌱 Tim's Dev Wiki

Search IconIcon to open search

DNS

Last updated January 6, 2023.

DNS (domain name system) is a distributed system that maps domain names to IP addresses, e.g. a DNS query for timz.dev can resolve to 76.76.21.21. Think of DNS as a distributed database, actually. The whole point of the DNS system is to allow for you to talk to computers through human-readable domain names. That extra layer of indirection also allows for more security and for changing the underlying machine without affecting users (timz.dev could be migrated to a different host).

The DNS system consists of a globally spanning network of DNS servers, also called name servers, each of which is responsible for handling the mappings belonging to their part of the hierarchical namespace.

Initially, all domain name to IP address mappings were stored in a single hosts.txt file managed by Stanford Research Institute. This centralised approach DNS system clearly wouldn’t scale well, so now we have a distributed network of name servers instead.

# DNS Resource Records

Authoritative name servers hold resource records for each domain name it manages. They’re just some important information the nameserver knows about the domain. They’re kept in a ‘zone file’ on the nameserver’s file system.

There are different kinds of resource records:

Resource records have a TTL (time to live) field which instructs the resolver on how long it should cache that knowledge for.

# DNS Resolution

Suppose you want to visit timz.dev for the first time.

  1. You start a Chrome web browser process and search for timz.dev.
  2. Chrome asks the local DNS resolver for the IP address of timz.dev.
    • The local DNS resolver is just a process running on your machine, or in your local network, which helps you resolve DNS requests.
  3. If the mapping doesn’t exist in the cache, the DNS resolver forwards the request to the root DNS server.
  4. The root DNS server tells the resolver which TLD DNS server for *.dev to talk to.
  5. The TLD DNS server tells the resolver which authoritative nameserver to talk to.
  6. The authoritative nameserver gives the resolve the IP address, which it caches for next time.

There are 2 ways resolution happens — iteratively or recursively. ( source)

# DNS Protocol

The DNS protocol is an application layer protocol. Just like HTTP or SMTP, it works in a request/response manner and packets have a header component and a payload component.

# Flashcards