Domain Name Service / Port 53

Protocol for converting hostname to IP address and viceversa. DNS uses UDP by default, fall back to TCP if on udp cannot communicate.
Advantages of DNS
1. To send packet across network we need IP Address and only DNS can provide.
2. No need for memorizing IP addresses
Disadv of DNS:
1. Registry only controlled by [ICANN](Terms) which can become bais to some country/organization.
2. DNS Messages does not have information of client asking the information, hacker can bisect the message and send his own message.
3. [TLD’s](Terms) can be bottleneck.

Name resolution

The process of looking up a hostname and finding corresponding IP address.

Forward Lookup

hostname/URL to IP conversion
sequenceDiagram
  participant u as User
  participant o as Office DNS Server
ISP
DNS Server
Recursive DNS Server participant r as Root Nameserver participant tld as .com TLD Server participant auth as Authoritative
DNS server Note over u: open yahoo.com
domain to IP mapping not found
Create |MAC|IP|udp dstport=53|
|DNS Query{hdr question=1}
{body qname:yahoo.com,Type=A,class=IN}| u ->> o: DNS Query(yahoo.com) Note over o: Cannot find domain to IP
Find Rootname server IP from
zone file o ->> r: DNS QUery(yahoo.com) Note over r: Find TLD server
for .com r ->> tld: DNS Query(yahoo.com) tld -->> r: IP of Authoritative
DNS server r -->> o: IP of Authoritative
DNS server o ->> auth: DNS Query(yahoo.com) auth -->> o: DNS Response
|Type=A,TTL:23,Address:x.x.x.x| o -->> u: DNS Response
|{hdr question=1}
{body ans:1,ans:x.x.x.x}|

Reverse Lookup

IP to URL/hostname conversion
Case-1: Spam received in mailbox, From-IP header is parsed. Now Email client wants to know from where this Email arrived? Is this IP Address authentic or spam. So Machine enquires ISP for reverse query, giving IP address and asking for URL(if exists)).
sequenceDiagram
  participant u as User/Desktop
  participant o as Office DNS Server
ISP
DNS Server
Recursive DNS Server Note over u: Got mail from 1.2.3.4
Create reverse DNS
4.3.2.1.in-addr.arpa. u ->> o: 4.3.2.1.in-addr.arpa. Find URL o ->> u: yahoo.com

Terms

CyberSquatting

Selling a domain to interested party at much higher price.

DNS Zone File

Plain text file which stores resource records of particular domain. Zone file always start with a Start of Authority (SOA) record.

; Authoritative data for test.com
    test.com.     86400    IN    SOA        star boss (9527,7200,7200,241920,86400)
    star                   IN    A          130.37.56.201       //IP Address of star.test.com is <>
    flits         86400    IN    A          130.37.16.112       //flits.test.com has IP address <>
    test.com.     86400    IN    MX         1 rambo                //Email should be 1st sent to rambo@test.com
    test.com.     86400    IN    MX         2 sambo                //if rambo@test.com fails sambo should be tried as 2nd choice
    test.com.     86400    IN    NS         star
    www           86400    IN    CNAME      star.cs.vu.nl        //www is aliased to star.cs.vu.nl
10.30.20.10.in-addr.arpa.  IN    PTR        host.domain.com
      

DNS Queries Types

1. Recursive: Recursive NS perform recursive queries to other nameservers and returns complete result to DNS client. Done by Local DNS server.
2. Iterative/Non-Recursive: Root nameservers does not collects all information rather they return partial information and continue to next query. This is called iterative.

Name server / Nameserver

Computer responsible for a particular domain, ie responding to that domain queries. One zone can have 1 or more name servers.

Types of Nameservers

1. Primary NS? Zone have 1 primary name server which gets its information from DNS zone file on its disk.
2. Secondary NS? Get their information from the primary name server, maybe internet facing.
3. Root NS? Server which have IP-Addresses of nameservers handling [TLDs](/Networking/OSI-Layers/Layer5/Protocols/DNS/Terms/Domain_Name). eg: .com, .org
4. Authoritative NS? Server authoritative for particular domain. Eg: nandini.com is handled by 4.4.4.4
5. Recursive NS? NS which takes query from client and returns complete result, does not return partial results.
6.Caching NS? Server sitting at front of Clients, doing DNS queries on behalf of clients, storing results locally in cache. As Cache grows its efficiency improves as it can answer lot from cache.
  Problem2: Cache Poisoning: Hackers fills in cache of caching nameserver from stale/wrong/bad entries. Solution: DNSSEC(DNS Security Extension) validation: Doing authentication, integration check of resource records before placing on cache.

Recursive, Authoritative DNS Server

RECURSIVE DNS SERVER? Recursive means referring to itself. This DNS server caches the DNS records and sends DNS query further if record is not found.
AUTHORITATIVE DNS SERVER? This server holds information about domain(eg: google.com) and delivers it to internet.