C.W.K.
Stream
Lesson 05 of 12 · published

DNS

~15 min · dns, name-resolution, hosts-file, mdns

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

인터넷의 전화번호부

DNS(Domain Name System)는 사람이 읽는 이름 (github.com) 을 IP 주소 (140.82.121.3) 로 번역해줘. DNS 없으면 모든 URL 이 숫자 문자열일 거야. 있으니까 이름만 외우면 돼.

도메인 입력했을 때 벌어지는 일

브라우저가 github.com 열면 lookup chain 이 발사돼:

  1. OS 캐시 — 이 머신이 최근에 풀었어?
  2. 라우터 캐시 — 라우터가 최근에 풀었어?
  3. Recursive resolver — ISP 의 DNS, 또는 public (1.1.1.1, 8.8.8.8). 무거운 일 다 함.
  4. Root nameserver — ".com 은 .com TLD 서버한테 물어봐."
  5. TLD nameserver — "github.com 은 GitHub 의 authoritative 한테 물어봐."
  6. Authoritative nameserver — 실제 IP 반환.

이 전체 춤이 millisecond 단위고 모든 layer 에서 캐시돼. 브라우저는 보통 step 3 (recursive resolver) 까지만 쳐 — recursive resolver 가 그 아래 전부 캐시하니까.

/etc/hosts — DNS 보다 먼저 있던 override

DNS 전엔 모든 머신이 /etc/hosts 파일에 이름→IP 매핑을 손으로 적었어. 지금도 있고 DNS 보다 먼저 검사돼. 로컬 override 한테 무지 유용해 — 테스트용으로 도메인을 다른 IP 로 보내거나, 광고 서버 차단하거나, LAN 의 장치 이름 짓거나.

mDNS / .local 주소

mDNS(Multicast DNS) 는 같은 LAN 의 장치들이 DNS 서버 없이 이름으로 서로 찾게 해줘. macOS 에선 Bonjour. 같은 네트워크의 모든 맥은 hostname.local 로 도달 가능. ssh office.local 이 DNS 한 줄, SSH config 한 줄도 없이 그냥 동작 — 그게 mDNS.

Code

/etc/hosts 안전하게 편집·bash
# View the file
cat /etc/hosts

# Typical content:
#   127.0.0.1    localhost
#   ::1          localhost
#   192.168.1.100  office.local

# Add a local override (requires sudo)
sudo nano /etc/hosts

# After saving, flush macOS DNS cache so changes take effect:
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
dig 와 nslookup 으로 진단·bash
# Detailed query
dig github.com

# Just the answer
dig +short github.com

# Use a specific resolver (Cloudflare)
dig @1.1.1.1 +short github.com

# Reverse lookup (IP → name)
dig -x 140.82.121.3

# Which DNS server is your machine using? (macOS)
scutil --dns | head -20

External links

Exercise

dig +short github.com 돌려서 IP 메모. 그다음 dig +short @1.1.1.1 github.com — 같은 답? /etc/hosts 편집해서 127.0.0.1 testblock.example 추가 (sudo 필요), 위의 macOS 명령으로 DNS flush, ping testblock.example 이 localhost 로 풀리는지 확인. 끝나면 그 줄 제거.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.