Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
430 views
in Technique[技术] by (71.8m points)

Run multiple DNS servers with pi-hole and docker

Setup

I have a Unifi Home Setup with multiple Wifi Networks set up and a RaspberryPi with Arch to take care of DNS filtering.

Goals

I want to run multiple DNS Servers on the Raspberry Pi and direct the different Wifis to different DNS. To this end I need different IP addresses for different DNS containers.

What I have done so far

After trying systemd and a couple of different docker solutions, I have settled on using Pi-Hole in combination with cloudflared.

Running multiple pi-holes is not a problem with docker-compose, but I know far too little about proper (docker) networking to figure out how to get different, network reachable ip-addresses to different containers.

Here is the docker-compose file for one set of cloudflare + pi-hole:

version: "3.5"
services:
  cloudflared_workday:
    container_name: cloudflared_workday
    image: crazymax/cloudflared:latest
    ports:
      - "5053:5053/udp"
      - "49312:49312/tcp"
    environment:
      - "TZ=Europe/Berlin"
      - "TUNNEL_DNS_UPSTREAM=https://1.1.1.1/dns-query,https://1.0.0.1/dns-query"
    restart: always

  pihole_workday:
    container_name: pihole_workday
    image: pihole/pihole:latest
    depends_on:
      - cloudflared_workday
    network_mode: host
    environment:
      TZ: 'Europe/Berlin'
      WEBPASSWORD: 'password'
      DNS1: '127.0.0.1#5053'
      DNS2: 'no'
      ServerIP: '192.168.2.10'
    # Volumes store your data between container upgrades
    volumes:
      - './pihole_workday/pihole/etc-pihole/:/etc/pihole/'
      - './pihole_workday/pihole/etc-dnsmasq.d/:/etc/dnsmasq.d/'
    restart: always

Where 192.168.2.10 is the ip given to the RaspberryPi.

I can only specify an IP for a DNS in my router, not different ports that I could remap for the containers.

PS.: I know the password is not ideal, but that's a problem for another day :D

Question

How do I run a duplicate of this setup on the same machine without the two DNS getting into each others' way and how do I reach the separate pi-holes with different IPs?

Edit 1

I found that there is something called macvlan in docker linking docker containers directly to the network. This seems to also work with pi-hole (macvlan + pi-hole), only that I haven't succeeded yet. Does anyone see a conceptual issue with this approach?

question from:https://stackoverflow.com/questions/65941599/run-multiple-dns-servers-with-pi-hole-and-docker

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...