Cara Mudah Bikin DNS Server Lokal Pakai CoreDNS

5 Januari 2019 • 2 menit untuk membaca artikel ini

Wtf is coreDNS?

CoreDNS is a DNS server. It is written in Go. It can be used in a multitude of environments because of its flexibility. CoreDNS is licensed under the Apache License Version 2, and completely open source. – coredns.io

Singkat cerita, aku pengen ketika temenku buka browser, ngetik alamat fe.anuanku.dev dia akan disajikan halaman web dari komputer dengan alamat 192.168.100.137. Terus, kalau temenku akses api.anuanku.dev akan disajikan API dari komputer dengan alamat 192.168.100.137. Paham kan ya? seolah-olah kaya akses vhost di vps.

Kenapa gk pakai cara edit file hosts saja? ribet cuy. Ya masa aku nyuruh temenku edit host file. Gak enak juga nyuruh-nyuruh haha. Lanjut ke step by step yang ku tempuh:

Persiapan directory

mkdir ~/coredns/coredns-config

Bikin ~/coredns/docker-compose.yaml yang berisi

version: '3.7'
services:
  coredns: 
    image: coredns/coredns
    restart: always
    command: -conf /coredns-config/Corefile
    ports:
      - 53:53/udp
    volumes:
      - ./coredns-config:/coredns-config/

Bikin ~/coredns/coredns-config/Corefie yang berisi

.:53 {
    forward . 9.9.9.9
    log
    errors
}

anuanku.dev:53 {
    file /coredns-config/anuanku.dev.db
    log
    errors
}

Bikin ~/coredns/coredns-config/anuanku.dev.db yang berisi

anuanku.dev.        IN  SOA dns.anuanku.dev. sumar.anuanku.dev. 2019110517 7200 3600 1209600 3600
fe.anuanku.dev.	IN	A	192.168.100.137
api.anuanku.dev.	IN	A	192.168.100.137

Selesai persiapan, langsung eksekusi

docker-compose -f ~/coredns/docker-compose.yaml up -d

Hasilnya jika di test:

drill @127.0.0.1 fe.anuanku.dev
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 35602
;; flags: qr aa rd ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 
;; QUESTION SECTION:
;; fe.anuanku.dev.	IN	A

;; ANSWER SECTION:
fe.anuanku.dev.	0	IN	A	192.168.100.137

;; AUTHORITY SECTION:

;; ADDITIONAL SECTION:

;; Query time: 2 msec
;; SERVER: 127.0.0.1
;; WHEN: Tue Nov  5 19:30:57 2019
;; MSG SIZE  rcvd: 56

Udah selesai, tinggal ganti dns router ke ip address komputer yang ngejalanin coreDNS. Ataus suruh temenku ganti dns-nya di network manager (tapi gak enak nyuruh2, haha). Sisanya ya kombinasikan aja sama vhost, entah nginx, httpd, atau traefik.

Cool~

Techdockercoredns

Sumarsono

System Administrator
Kembali ke atas

Vuejs Docker>>

<<Logrotate Traefik