DNS in 5 minutes

DNS, the Domain Name System, has been described as “the address book of the internet”. It’s both a naming scheme — the hierarchy of .com or .co.uk domains you are used to seeing — as well as the networking protocol used by computers to talk to each other.

When you visit a website, such as https://duckduckgo.com, your computer does not go to the duckduckgo.com server immediately. Instead, it has to make two network requests:

  • First, it makes a request to a DNS server asking for the address of duckduckgo.com, which returns an IP address such as (for example) 10.20.30.40.
  • Once your computer has received this IP, it makes the connection to 10.20.30.40.

These requests are made by your operating system, transparently, when programs make network requests. It will also cache the results locally, so you can make multiple requests to a website without overloading the DNS server. This is why you can write a program to access a website without worrying about all this DNS stuff yourself.

dog is a command-line DNS client that performs no caching and makes no additional network requests other than the ones you specify.

Record types

The DNS protocol can contain multiple pieces of data about a domain, each called records. IPv4 addresses are contained in what’s called A records. If your computer supports IPv6, it will also ask for the IPv6 address as part of an AAAA record. These two record types are queried for by operating systems and web browsers.

Other record types include MX records that contain the name of the e-mail server for a domain, CNAME records that can alias one domain to another, and TXT records that contain textual data.

Unlike a web browser, which connects to the server specified in a record, dog merely displays the data it receives.

Nameservers

Each DNS request needs to be sent somewhere: another computer must answer its call. If you’re using a computer at home, your ISP will be running a DNS server that your router will use, forwarding requests to it and returning the results to your computer once they are received.

There are also several third-party DNS servers available across the Internet that you can switch to if you so desire.

dog will use the default nameserver specified by your computer, but this can be overridden to compare the responses recieved from different nameservers.

dog and dig

The ‘standard’ command-line DNS client is dig, which stands for domain information groper. There is a good chance you already have it installed on your computer, or at least have it available through a package manager.

These two tools serve much the same purpose, except dog doesn’t stand for anything in particular. Maybe domain object graph?