lopezjo49/unbound

By lopezjo49

Updated 27 days ago

Unbound DNS Server for forwarding requests from pi-hole to ISP or upstream cloudflared workloads.

Image
Networking
1

1.8K

lopezjo49/unbound repository overview

Summary

Unbound DNS Server for forwarding requests from pi-hole to ISP or upsrteam cloudflared workloads.

MAJOR UPDATE

2024/04/07 - Converted to using alpine base over ubuntu. Tag v20 is final ubuntu base

Conf (pihole.conf)

Forward to local cloudflared workloads OR ISP/pub DNS servers

Upstream cloudflared workloads running on IPs: 172.18.0.15 & 16
forward-zone:
    name: "."
    forward-addr: 172.18.0.15@5553
    forward-addr: 172.18.0.16@5553
Upstream ISP/Pub DNS
forward-zone:
    name: "."
    forward-addr: 192.168.2.1
    forward-addr: 1.1.1.1
Entrypoint (start.sh)
#!/bin/sh

# Get Root Hints
wget -S -N https://www.internic.net/domain/named.cache -O /etc/unbound/root.hints 2>/dev/null

# Fetch new KSK Key
mkdir -p /var/lib/unbound
/usr/sbin/unbound-anchor -a /var/lib/unbound/root.key;
chown -R unbound:unbound /var/lib/unbound
service unbound start

tail -f /var/log/unbound.log;
DNSSEC: Unbound Config (ex. /etc/unbound.conf) requires the following
## key for DNSSEC:
auto-trust-anchor-file: "/var/lib/unbound/root.key"

Docker networks used in following example
docker network create --subnet=172.18.0.0/23 --ip-range=172.18.1.0/24 --gateway 172.18.0.1 dns

Run ex.

docker run -d \
--name unbound1 -h unbound1 \
--network dns \
--restart=unless-stopped \
--ip 172.18.0.11 \
-e DEBIAN_FRONTEND="noninteractive" \
-v /docker/data/unbound/pi-hole.conf:/etc/unbound/unbound.conf.d/pi-hole.conf:ro \
lopezjo49/unbound:latest
Run a second (redundant) workload by changing names and ip
docker run -d \
--name unbound2 -h unbound2 \
--network dns \
--restart=unless-stopped \
--ip 172.18.0.12 \
-e DEBIAN_FRONTEND="noninteractive" \
-v /docker/data/unbound/pi-hole.conf:/etc/unbound/unbound.conf.d/pi-hole.conf:ro \
lopezjo49/unbound:latest

Unbound using Compose

x-unbound-common: &unb
  build:
    dockerfile: Dockerfile.alpine
  image: lopezjo49/unbound:latest
  restart: unless-stopped
  env_file: .env
  environment:
    DEBIAN_FRONTEND: noninteractive
  volumes:
    - ./alpine-pi-hole.conf:/etc/unbound/unbound.conf:ro
  
services:
  pihole1:
    hostname: unbound1
    container_name: unbound1
    <<: *unb
    networks:
      dns:
        ipv4_address: 172.18.0.11

  pihole2:
    hostname: unbound2
    container_name: unbound2
    <<: *unb
    networks:
      dns:
        ipv4_address: 172.18.0.12

networks:
  dns:
    name: dns 
    external: true

Pi-Hole

  • Go to Settings, DNS Tab
  • Update upstream DNS Servers (use '#')
    • Custom1 (IPv4) = 172.18.0.11#5335
    • Custom2 (IPv4) = 172.18.0.12#5335

Tests

delv www.nixcraft.com @172.18.0.11 -p 5335 AAAA +multi
delv www.nixcraft.com @172.18.0.11 -p 5335 +multi +dnssec
delv dnsworkshop.org @172.18.0.11 -p 5335 +multi +vtrace
delv www.nixcraft.com @172.18.0.11 -p 5335 +multi +vtrace
Cloudflare Ex. w/exporting prometheus metrics
docker run -d \
    --name doh1 -h doh1 \
    --network dns \
    --ip 172.18.0.15 \
    -p 3338:3338 \
    -e TZ="America/New_York" \
    -e DEBIAN_FRONTEND="noninteractive" \
    -e TUNNEL_DNS_UPSTREAM="https://1.1.1.2/dns-query,https://1.0.0.2/dns-query" \
    -e TUNNEL_DNS_ADDRESS=0.0.0.0 \
    -e TUNNEL_DNS_PORT=5553 \
    -e TUNNEL_METRICS=0.0.0.0:3338 \
    --restart=always \
    cloudflare/cloudflared:latest proxy-dns
docker run -d \
    --name doh2 -h doh2 \
    --network dns \
    --ip 172.18.0.16 \
    -p 3339:3339 \
    -e TZ="America/New_York" \
    -e DEBIAN_FRONTEND="noninteractive" \
    -e TUNNEL_DNS_UPSTREAM="https://1.1.1.2/dns-query,https://1.0.0.2/dns-query" \
    -e TUNNEL_DNS_ADDRESS=0.0.0.0 \
    -e TUNNEL_DNS_PORT=5553 \
    -e TUNNEL_METRICS=0.0.0.0:3339 \
    --restart=always \
    cloudflare/cloudflared:latest proxy-dns

Cloudflare using Compose

x-defaults: &default_config
  image: cloudflare/cloudflared:latest
  restart: always
  env_file: .env
  entrypoint: ["cloudflared", "proxy-dns"]
services:
  doh1:
    <<: *default_config
    container_name: doh1
    hostname: doh1
    ports:
      - 3338:3338
    environment:
      - "TUNNEL_METRICS=0.0.0.0:3338"
    networks:
      dns:
        ipv4_address: 172.18.0.15
  doh2:
    <<: *default_config
    container_name: doh2
    hostname: doh2
    ports:
      - 3339:3339
    environment:
      - "TUNNEL_METRICS=0.0.0.0:3339"
    networks:
      dns:
        ipv4_address: 172.18.0.16

networks:
  dns:
    name: dns 
    external: true

env_file:

COMPOSE_PROJECT=cloudflare
export DEBIAN_FRONTEND="noninteractive"
export TZ="America/New_York"
export TUNNEL_DNS_UPSTREAM="https://CHANGETHIS.cloudflare-gateway.com/dns-query,https://1.0.0.2/dns-query"
export TUNNEL_DNS_ADDRESS="0.0.0.0"
export TUNNEL_DNS_PORT=5553

Disclaimer

Not For production or commercial use. Home network repo.

Tag summary

Content type

Image

Digest

sha256:377e3f915

Size

10.5 MB

Last updated

27 days ago

docker pull lopezjo49/unbound