Domain Name System (DNS)
I’ve had to see this term every time I deploy a website, but truth be told that I don’t know what this does. I finally get to understand how this works under the hood.
The DNS is
- a distributed database implemented in a hierarchy of DNS servers, and
- an application-layer protocol that allows hosts to query the distributed database.
ahh, so like when you do
ping google.com PING google.com (22.214.171.124): 56 data bytes
google.com is the Hostname, you do a lookup in the DNS, and get the IP address
Below are the exact steps:
- The browser extracts the hostname, www.someschool.edu, from the URL and passes the hostname to the client side of the DNS application.
- The DNS client sends a query containing the hostname to a DNS server.
- The DNS client eventually receives a reply, which includes the IP address for the hostname.
- Once the browser receives the IP address from DNS, it can initiate a TCP connection to the HTTP server process located at port 80 at that IP address.
And then you use something like nginx.
DNS is Decentralized
There are several advantages to a decentralized design:
- If a DNS server crashes, the entire internet doesn’t crash
- A single DNS server does not have to handle all DNS queries
- Multiple servers close to querying clients all across the globe
- Easier Maintenance
- Root DNS Servers provide the IP addresses of the TLD servers.
- Top-level domain (TLD) servers. For each of the top-level domains (
.net, etc.) there is TLD server (or server cluster). For example, Verisign maintains the
- Authoritative DNS servers. (ex:
If i am in Canada vs if I am in Europe and i enter
google.com, does that resolve to the same ip address?
No. This is thanks to a practice called Geolocation Routing.
Who pays for the DNS servers?
We just learned that DNS follows a hierarchy, so it depends:
- For root servers, it’s like volunteers.
- For TLD servers: this registrar (ex: GoDaddy) pays a fee to a domain name registry (ex: Verisign which maintains
.comdomain) which maintains TLD servers.
- For Authoritative servers: Domain registrars (ex: GoDaddy) maintain these. Remember that DNS is a mapping from a Hostname to an IP Address. You buy Hostname from domain providers like GoDaddy, and that is why you can configure the DNS there! It all makes sense now.
DNS Records and Messages
Type=A, then Name is a hostname and Value is the IP address for the host- name. Thus, a Type A record provides the standard hostname-to-IP address map- ping. As an example, (relay1.bar.foo.com, 126.96.36.199, A) is a Type A record.
- If Type=NS, then Name is a domain (such as foo.com) and Value is the host- name of an authoritative DNS server that knows how to obtain the IP addresses for hosts in the domain. This record is used to route DNS queries further along in the query chain. As an example, (foo.com, dns.foo.com, NS) is a Type NS record.
- If Type=CNAME, then Value is a canonical hostname for the alias hostname Name. This record can provide querying hosts the canonical name for a host- name. As an example, (foo.com, relay1.bar.foo.com, CNAME) is a CNAME record.
- If Type=MX, then Value is the canonical name of a mail server that has an alias hostname Name. As an example, (foo.com, mail.bar.foo.com, MX) is an MX record. MX records allow the hostnames of mail servers to have simple aliases. Note that by using the MX record, a company can have the same aliased name for its mail server and for one of its other servers (such as its Web server). To obtain the canonical name for the mail server, a DNS client would query for an MX record; to obtain the canonical name for the other server, the DNS client
would query for the CNAME record.