Communication using the Internet Protocol (IP) requires each endpoint to be identified by a numeric IP address. IP addresses are needed to actually deliver a message to a receiver, just like a numeric phone number is required to place a call.
In the early days of the Internet, entries were added to a “hosts file” that resided on a computer that associated a human-readable name to an IP. A user could access a site using the name in the hosts file instead of the IP address.
The domain name system is a distributed way to share these name-to-IP associations instead of requiring each computer to synchronize a hosts file. A name server publishes the IP address for a domain and provides a single location to update when an IP changes.
Domain names are issued by registrars and name servers provide the details about which IP is associated with the domain. Domain registrations are valid for 1 to 10 years and registrars typically provide name servers to their customers as well. (Some developers may choose to run their own name servers for greater control.)
Here’s a step-by-step description of how DNS works:
Instead of performing a full DNS lookup on every request, a computer may cache the results for a time period defined by the name server. A typical DNS entry looks like this:
www.example.com A 3600 10.20.30.40
This entry indicates that the result should be cached for 3600 seconds (1 hour). Administrators will often change the timeout value to a low number (minutes) before they change an IP address.
There are several other record types in addition to the A record. CNAME records let you point one domain name to another. Eventually the chain of CNAME records is resolved by an A record that points to an actual IP address.
MX records are used to set the IP address of the email server (usually different from the web server) and TXT records are used for informational purposes such as verifying ownership of a domain.
DNS is a backbone technology for the Internet and is especially relevant when setting up or configuring a server infrastructure. When purchasing a new domain, the registrar will often ask for the IP address of your server to be added to their name servers, or allow you to use your own name servers.
Most CDNs ask you to create a new DNS entry on your domain that points to the CDN. This makes it easy to load assets from the CDN using your own domain. Similarly, Platform-as-a-Service providers like Heroku let you point your domains to their servers so you can keep your domain brand while using their hosted infrastructure.
A domain name is the entry point to an online service and knowing how they work is crucial to integrating with external services.