|
| 1 | +--- |
| 2 | +title: "Domain Name System (DNS)" |
| 3 | +description: "Explore the Domain Name System (DNS) — the backbone of the Internet that translates human-readable names into IP addresses. Learn its structure, types of records, and how the DNS resolution process works." |
| 4 | +tags: [dns, networking, internet, domain, ip, infrastructure] |
| 5 | +sidebar_label: DNS |
| 6 | +--- |
| 7 | + |
| 8 | +The **Domain Name System (DNS)** is one of the most essential — yet often overlooked components of the Internet. It’s what allows us to use memorable names like `codeharborhub.github.io` instead of complex numerical IP addresses. |
| 9 | + |
| 10 | +DNS acts as the **Internet’s phonebook**, translating **domain names** into **IP addresses** so browsers can locate and communicate with servers worldwide. |
| 11 | + |
| 12 | +## Why DNS Exists |
| 13 | + |
| 14 | +Computers communicate using numbers (IP addresses), not words. Before DNS, users had to manually look up and remember numeric addresses — an unscalable and error-prone process. |
| 15 | + |
| 16 | +DNS was created to solve this by introducing a **distributed, hierarchical naming system** that’s: |
| 17 | +* **Human-friendly**: You type names, not numbers. |
| 18 | +* **Scalable**: Works across billions of domains. |
| 19 | +* **Automatic**: Queries happen invisibly in milliseconds. |
| 20 | + |
| 21 | +## DNS Hierarchy Overview |
| 22 | + |
| 23 | +The DNS system is hierarchical, like a tree: |
| 24 | + |
| 25 | +```mermaid |
| 26 | +graph TD |
| 27 | + A[Root Zone - .] --> B[Top-Level Domains - .com, .org, .io] |
| 28 | + B --> C[Second-Level Domains - example.com] |
| 29 | + C --> D[Subdomains - blog.example.com] |
| 30 | + D --> E[Hostnames - www, mail] |
| 31 | +``` |
| 32 | + |
| 33 | +Each level plays a specific role in locating resources on the Internet. |
| 34 | + |
| 35 | +## How a DNS Query Works (Step-by-Step) |
| 36 | + |
| 37 | +When you enter a URL such as **https://codeharborhub.github.io**, your browser performs several steps to find its IP address: |
| 38 | + |
| 39 | +```mermaid |
| 40 | +sequenceDiagram |
| 41 | + participant User |
| 42 | + participant Browser |
| 43 | + participant Resolver |
| 44 | + participant RootServer |
| 45 | + participant TLDServer |
| 46 | + participant AuthoritativeServer |
| 47 | +
|
| 48 | + User->>Browser: Enter codeharborhub.github.io |
| 49 | + Browser->>Resolver: Request IP address |
| 50 | + Resolver->>RootServer: Ask for .io TLD info |
| 51 | + RootServer-->>Resolver: Return .io TLD name servers |
| 52 | + Resolver->>TLDServer: Ask for github.io info |
| 53 | + TLDServer-->>Resolver: Return authoritative server |
| 54 | + Resolver->>AuthoritativeServer: Ask for codeharborhub.github.io |
| 55 | + AuthoritativeServer-->>Resolver: Return IP address |
| 56 | + Resolver-->>Browser: 185.199.108.153 |
| 57 | + Browser->>185.199.108.153: Send HTTP Request |
| 58 | +``` |
| 59 | + |
| 60 | +All this happens in a fraction of a second. |
| 61 | + |
| 62 | +## The Four Key DNS Server Types |
| 63 | + |
| 64 | +| Server Type | Description | |
| 65 | +|--------------|--------------| |
| 66 | +| **DNS Resolver (Recursive Resolver)** | Usually provided by your ISP or a public DNS service (like Google `8.8.8.8`). It initiates and manages DNS lookups on your behalf. | |
| 67 | +| **Root Name Server** | The top-level of DNS — knows where to find TLD servers (like `.com`, `.io`, `.net`). | |
| 68 | +| **TLD Name Server** | Stores information about domains under a specific top-level domain. | |
| 69 | +| **Authoritative Name Server** | The final authority — provides the actual IP address for a domain. | |
| 70 | + |
| 71 | +## Common DNS Record Types |
| 72 | + |
| 73 | +DNS uses **resource records (RRs)** to store information. Each type serves a specific purpose: |
| 74 | + |
| 75 | +| Record Type | Description | Example | |
| 76 | +|--------------|--------------|----------| |
| 77 | +| **A** | Maps a domain to an IPv4 address. | `codeharborhub.github.io → 185.199.108.153` | |
| 78 | +| **AAAA** | Maps a domain to an IPv6 address. | `example.com → 2606:2800:220:1:248:1893:25c8:1946` | |
| 79 | +| **CNAME** | Alias for another domain name. | `www.example.com → example.com` | |
| 80 | +| **MX** | Mail server record (used for email routing). | `example.com → mail.example.com` | |
| 81 | +| **TXT** | Stores arbitrary text info (SPF, DKIM, verification). | `v=spf1 include:_spf.google.com ~all` | |
| 82 | +| **NS** | Identifies the authoritative name servers for a domain. | `example.com → ns1.example.net` | |
| 83 | + |
| 84 | +## DNS Caching — Speed Optimization |
| 85 | + |
| 86 | +To reduce lookup time and network load, DNS results are **cached** at multiple levels: |
| 87 | +* **Browser Cache** – Short-term memory for recently visited domains. |
| 88 | +* **Operating System Cache** – Local DNS records stored temporarily. |
| 89 | +* **Resolver Cache** – Managed by ISPs or public DNS resolvers. |
| 90 | + |
| 91 | +Each record has a **TTL (Time To Live)** that defines how long it stays valid before a recheck. |
| 92 | + |
| 93 | +## Practical Example — DNS Lookup Flow |
| 94 | + |
| 95 | +<Tabs> |
| 96 | + <TabItem value="nontechnical" label="Simple View" default> |
| 97 | + You type `codeharborhub.github.io` → DNS finds its IP → Browser connects → Website loads. |
| 98 | + It’s that simple — all automatic. |
| 99 | + </TabItem> |
| 100 | + <TabItem value="technical" label="Technical Flow"> |
| 101 | + 1. The browser checks its cache. |
| 102 | + 2. If not found, it asks the **local resolver**. |
| 103 | + 3. The resolver queries **root**, **TLD**, and **authoritative** servers. |
| 104 | + 4. The IP is returned and cached. |
| 105 | + 5. The browser sends the HTTP request to that IP. |
| 106 | + </TabItem> |
| 107 | +</Tabs> |
| 108 | + |
| 109 | +## DNS in Action — Simulation |
| 110 | + |
| 111 | +```jsx live |
| 112 | +function DnsDemo() { |
| 113 | + const [resolved, setResolved] = React.useState(false); |
| 114 | + const resolve = () => setResolved(true); |
| 115 | + |
| 116 | + return ( |
| 117 | + <div style={{ textAlign: "center" }}> |
| 118 | + <h3>DNS Resolution Simulation</h3> |
| 119 | + <p>Domain: codeharborhub.github.io</p> |
| 120 | + <button onClick={resolve}>Resolve Domain</button> |
| 121 | + {resolved && <p> IP Address: 185.199.108.153</p>} |
| 122 | + </div> |
| 123 | + ); |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +## Security in DNS |
| 128 | + |
| 129 | +DNS was designed for speed and reliability — not security. Attackers exploit this through methods like: |
| 130 | + |
| 131 | +* **DNS Spoofing / Cache Poisoning:** Injecting false IP mappings. |
| 132 | +* **DNS Hijacking:** Redirecting users to malicious servers. |
| 133 | +* **Amplification Attacks:** Overloading DNS servers to cause downtime. |
| 134 | + |
| 135 | +To counter these, **DNSSEC (Domain Name System Security Extensions)** was introduced. It digitally signs DNS data, ensuring authenticity and integrity. |
| 136 | + |
| 137 | +## Key Takeaways |
| 138 | + |
| 139 | +* DNS is the **Internet’s distributed naming system** that maps domain names to IP addresses. |
| 140 | +* The DNS hierarchy consists of **Root**, **TLD**, and **Authoritative** servers. |
| 141 | +* DNS uses various **record types** (A, AAAA, CNAME, MX, TXT) to manage different data. |
| 142 | +* **Caching** makes DNS fast, while **DNSSEC** makes it secure. |
| 143 | +* Every click, website, or API request starts with a DNS lookup — it’s the silent foundation of the web. |
| 144 | + |
| 145 | +:::tip |
| 146 | +Learn about [IP Addressing](./ip-addresses.mdx) — the numerical system that identifies every device on the Internet. |
| 147 | +::: |
0 commit comments