sumarsono.com
Take it with a grain of salt


Pihole Docker Dan Doh Pihole Docker

Posted on

Pihole Docker

Pihole Docker menggunakan docker-compose, dari developer pihole sudah menyediakan template yaml-nya. Untuk install pihole pakai docker caranya cukup mudah, syaratnya sudah install docker dan docker-compose.

Silakan gunakan docker-compose.yaml berikut ini (ini copas dari pihole docker):

version: "3"

# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
services:
  pihole:
    container_name: pihole
    image: pihole/pihole:latest
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "10080:80/tcp"
      - "10443:443/tcp"
    environment:
      TZ: 'Asia/Jakarta'
      WEBPASSWORD: 'set pass web ui mu disini'
    # Volumes store your data between container upgrades
    volumes:
      - './etc-pihole/:/etc/pihole/'
      - './etc-dnsmasq.d/:/etc/dnsmasq.d/'
    # Recommended but not required (DHCP needs NET_ADMIN)
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    cap_add:
      - NET_ADMIN
    restart: unless-stopped

Aku hanya menyesuaikan port webui, timezone, dan password untuk webui.

Next, tinggal up aja

docker-compose up -d

Tes query dns pakai pihole

dig @127.0.0.1 sumarsono.com


; <<>> DiG 9.11.5-P4-5.1+deb10u2-Debian <<>> @127.0.0.1 sumarsono.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58090
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;sumarsono.com.			IN	A

;; ANSWER SECTION:
sumarsono.com.		20	IN	A	54.179.122.191
sumarsono.com.		20	IN	A	13.250.205.9

;; Query time: 74 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Tue Jan 05 09:28:15 WIB 2021
;; MSG SIZE  rcvd: 100

Enable DoH Pihole Docker

Untuk menggunakan DoH Pihole, aku akan memakai cloudflared

siapkan direktory dan config untuk cloudflared:

mkdir /etc/cloudflared/
nano /etc/cloudflared/config.yml

isi dari /etc/cloudflared/config.yml:

proxy-dns: true
proxy-dns-address: 0.0.0.0
proxy-dns-port: 5053
proxy-dns-upstream:
  - https://1.1.1.1/dns-query
  - https://1.0.0.1/dns-query
  #Uncomment following if you want to also want to use IPv6 for  external DOH lookups
  #- https://[2606:4700:4700::1111]/dns-query
  #- https://[2606:4700:4700::1001]/dns-query

Perhatikan bagian proxy-dns-address aku sengaja bind semua address supaya mudah dipakai oleh pihole docker. Kemudian bagian proxy-dns-port aku set ke 5053 supaya tidak bentrok dengan dns server pihole docker.

Lanjut install cloudflared

wget https://bin.equinox.io/c/VdrWdbjqyF/cloudflared-stable-linux-amd64.deb
apt-get install ./cloudflared-stable-linux-amd64.deb
cloudflared -v

Eksekusi cloudflared

cloudflared service install --legacy
systemctl enable --now cloudflared
systemctl status cloudflared

Tes query DNS pakai cloudflared

dig @127.0.0.1 -p 5053 sumarsono.com


; <<>> DiG 9.11.5-P4-5.1+deb10u2-Debian <<>> @127.0.0.1 -p5053 sumarsono.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21764
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;sumarsono.com.			IN	A

;; ANSWER SECTION:
sumarsono.com.		20	IN	A	128.199.185.38
sumarsono.com.		20	IN	A	157.230.35.153

;; Query time: 103 msec
;; SERVER: 127.0.0.1#5053(127.0.0.1)
;; WHEN: Tue Jan 05 09:28:53 WIB 2021
;; MSG SIZE  rcvd: 100

Selanjutnya ganti upstream dns pihole ke cloudflared supaya bisa pakai DoH, pertama aku harus dapetin ip address docker0

ip a show docker0

# outputnya
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:19:12:23:45 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

IP address dari docker0 adalah 172.17.0.1, aku akan pakai IP ini sebagai upstream dns dari pihole, aku buka webui pihole, kalau aku kebetulan di http://192.168.1.254:10080/admin/. Login > Settings > DNS

Setting Upstream DNS server PiHole

isikan 172.17.0.1#5053

Terakhir, ganti DNS Server Router supaya pakai DNS dari PiHole supaya semua device yang terhubung mendapatkan manfaat dari PiHole yang tadi diinstall

DNS Router

Selesai, itu tadi caraku install pihole docker dan enable DoH pihole docker. Sangat mudah.