What is DNS?
DNS stands for Domain Name System (or Domain Name Server when referring to a server which is part of the Domain Name System). The Domain Name System is a hierarchical distributed naming system for devices, services, or any resource connected to the Internet or a private network. Primarily DNS serves the purpose of translating domain names to their underlying IP addresses so that services behind them can be located. This system serves as a sort of index or directory for the Internet or for local networks.
To clarify further, think of the example of your mobile phone. It can be quite difficult to memorize many phone numbers, so to simplify things you save them to your phone and give them a name. When you want to call a person you just look up their name in your contacts list and your phone knows which number is behind the name.
It's also possible to access a website directly using its IP address, but a domain name is easier to remember, IPs aren't necessarily static (i.e. they can change), and many servers have multiple websites (but only a single IP address). Therefore domain names and DNS servers are useful.
How Does DNS Work?
When you first connect your router to the Internet, your ISP will assign you an IP address but they will typically also provide the address of a name server. Name servers are used to determine which IP a particular domain name resolves to. But how do these name servers know know the addresses of the billion websites which exist?
Most name servers will maintain a small database containing the domain names and associated IP addresses which are most often used on their own networks while delegating name resolution for other names to other DNS servers on the web. Some name servers will instead maintain a list of hosts and addresses which it is the designated authority for.
For most DNS servers here is the typical workflow:
When a user tries to access a website for the first time, their computer first sends a request to their name server. The name server then checks its own database to see if it knows the IP which the domain should point to. If it does it immediatly sends the result back, if not it sends a request to another nearby name server to see if it knows the domain. This other name server then performs the same steps, checking its own database and asking another name server if it doesn't know the answer. If, after a reasonable number of attempts, no answer is found then an error is returning to the user.
When a DNS server contacts another DNS server it caches the results of the lookup for some time so it can quickly resolve subsequent requests to the same domain. This caching is known as Time-To-Live (or TTL) which can range from minutes to days. Over time, the results from looking up hosts from their origin (referred to as SOA which will be explained later) will be propagated to other DNS servers until the resolution is spread across the Internet.
How Are Domains Created?
Domains are registered through authoritative name servers which are assigned responsibility for certain domains. When a person registers a domain name they typically use the DNS servers provided by the registrar (this is referred to as a parked domain). This DNS server (or servers) is referred to as the SOA, or Start of Authority, for the domain. Information about your domain (e.g. lists of subdomains, email redirects, etc.) is stored in a zone file on the DNS server.
These zone files can contain a variety of different configurations referred to as records. Here are some of the most common record types:
|A||Address||This record type is used to identify the IP address which the domain should point to.|
|CNAME||Canonical Name||A CNAME is basically an alias for your domain. If someone accesses this alias they will be directed to the server indicated by the A-record.|
|MX||Mail Exchanger||This record type maps email traffic to a specific server.|
|NS||Name Server||This record has information about the name server. This is used to inform other DNS servers that your name server is the SOA for your domain.|
|SOA||Start of Authority||This record is at the beginning of every zone file and contains information about the primary name server for the zone along with some other information.|
|PTR||Reverse DNS Lookup||This is a pointer to a canonical name, but unlike CNAME records, only the name is returned here. This is used for performing reverse DNS lookups.|
|TXT||Text Record||This record type was originally intended for human-readable text, but has evolved to typically carry machine-readable data instead. As a webmaster you may use this record type for purposes such as verifying your Google Webmaster Tools account.|