DNS Basics — DevOps

Dari Domain ke IP Address Saat kamu ketik google.com di browser, komputer tidak tahu dimana server Google berada. DNS (Domain Name System) adalah buku telepon i

Dari Domain ke IP Address

Saat kamu ketik google.com di browser, komputer tidak tahu dimana server Google berada. DNS (Domain Name System) adalah buku telepon internet: translate nama domain ke IP address.

Resolusi DNS: Perjalanan Satu Query

Browser: "Apa IP google.com?"
    │
    ▼
Recursive Resolver (ISP / 1.1.1.1 / 8.8.8.8)
    │ (cek cache — kalau ada, balas langsung)
    ▼
Root DNS (.)              "Tanya TLD .com ke: 192.5.6.30"
    │
    ▼
TLD DNS (.com)            "Tanya authoritative google.com ke: ns1.google.com"
    │
    ▼
Authoritative NS          "google.com = 142.250.80.46"
    │
    ▼
Balas ke browser + cache di resolver sesuai TTL

Record Types (yang Sering Dipakai)

A       → map domain ke IPv4          myapp.com        → 203.0.113.5
AAAA    → map domain ke IPv6          myapp.com        → 2001:db8::1
CNAME   → alias ke domain lain        www.myapp.com    → myapp.com
MX      → mail server                 myapp.com        → mail.google.com (priority 10)
TXT     → teks bebas (verifikasi,     myapp.com        → "v=spf1 include:_spf.google.com ~all"
          SPF, DKIM, DMARC)
NS      → nameserver authoritative    myapp.com        → ns1.cloudflare.com
SRV     → service discovery           _sip._tcp.example → port + target (VoIP, chat)

TTL & Propagasi

TTL (Time To Live) = berapa detik resolver boleh cache jawaban sebelum query ulang. Misal TTL = 3600 → cache 1 jam.

"Propagasi DNS lambat" biasanya bukan masalah protocol — itu cache TTL yang belum expired di resolver di seluruh dunia.

A vs CNAME: Tradeoff

# A record — langsung ke IP
myapp.com       A      203.0.113.5

# CNAME — alias ke domain lain, resolver lookup lagi
www.myapp.com   CNAME  myapp.com
app.vercel.com  CNAME  cname.vercel-dns.com

Internal DNS

DNS tidak hanya untuk internet publik. Infrastruktur modern pakai internal DNS untuk service discovery:

DNS-Based Load Balancing

# Round-robin: multiple A records untuk domain sama
myapp.com   A   203.0.113.5
myapp.com   A   203.0.113.6
myapp.com   A   203.0.113.7
# Resolver pilih salah satu (atau client iterate jika pertama gagal)

# Geographic: Route 53 Geo Routing
#   User dari Asia → asia-server IP
#   User dari US → us-server IP

# Latency-based: pilih origin dengan latency terendah
# Failover: jika primary unhealthy, swap ke secondary

Load balancing via DNS sederhana tapi bukan yang paling presisi — health check di sisi DNS lag beberapa menit. Untuk failover cepat, kombinasikan dengan load balancer di layer 4/7.

Tools untuk Debugging DNS

# dig — paling informatif
dig google.com                  # A record
dig google.com MX               # mail record
dig google.com ANY              # semua record
dig @1.1.1.1 google.com         # pakai resolver tertentu
dig +trace google.com           # trace dari root ke authoritative

# nslookup — versi sederhana, ada di Windows juga
nslookup google.com
nslookup google.com 8.8.8.8

# host — ringkas
host google.com

# Cek DNS cache OS (Linux)
sudo systemd-resolve --statistics
sudo systemd-resolve --flush-caches

Contoh Pattern: Migrasi Domain ke Server Baru

# 1 minggu sebelum cutover: turunkan TTL
myapp.com   A   203.0.113.5   TTL=300

# Cutover: update A record
myapp.com   A   203.0.113.99  TTL=300

# Traffic beralih dalam ~5 menit (bukan 1 hari)

# Setelah stable: naikkan TTL lagi
myapp.com   A   203.0.113.99  TTL=86400

Yang akan kamu pelajari