DNS / Materi 7 dari 8
DNS Lokal: File hosts dan resolver
Mengatur DNS di komputer sendiri dan memakai DNS publik.
DNS / Materi 7 dari 8
Mengatur DNS di komputer sendiri dan memakai DNS publik.
Sebelum menanyai resolver, sistem operasi memeriksa file hosts. Isinya pemetaan nama ke IP yang berlaku hanya di komputer itu. Berguna untuk menguji website di server baru sebelum DNS diubah, atau mengarahkan contoh.test ke 127.0.0.1 saat development.
Server DNS yang dipakai komputer biasanya diberikan otomatis oleh router lewat DHCP. Kamu bisa menggantinya dengan DNS publik seperti 1.1.1.1 atau 8.8.8.8 bila DNS ISP lambat atau bermasalah. Di Linux, resolver yang aktif terlihat di /etc/resolv.conf atau lewat resolvectl status.
Kesalahan umum: lupa menghapus entri hosts setelah selesai testing, sehingga website tetap terbuka dari server lama dan bingung kenapa perubahan DNS tidak berefek di komputer sendiri. Mengedit hosts juga butuh hak administrator.
# Lokasi file hosts
Linux/macOS : /etc/hosts
Windows : C:\Windows\System32\drivers\etc\hosts
# Isi contoh
127.0.0.1 localhost
127.0.0.1 app.test
203.0.113.10 contoh.co.id www.contoh.co.id$ cat /etc/resolv.conf
nameserver 192.168.1.1
search lan
$ resolvectl status | head
Global
Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.1.1
# Menguji getent (memakai hosts + DNS seperti aplikasi biasa)
$ getent hosts app.test
127.0.0.1 app.testLogin untuk menyimpan progres belajar.
pingLatihan: Domain development
Buat entri hosts agar toko.test mengarah ke komputermu sendiri.
127.0.0.1 toko.test