Docker容器中的Pihole和Unbound-未绑定的未接收请求

时间:2019-01-06 22:27:54

标签: docker docker-compose unbound

我正在尝试在Raspberry pi 3上运行2个Docker容器,一个用于Unbound,一个用于Pihole。这个想法是,Pihole将首先使用Unbound作为其DNS服务器之前阻止所有请求。我一直在遵循Pihole的文档,以确保here可以运行,并且启动了两个容器,并且pihole正常工作。但是,在运行docker exec pihole dig pi-hole.net @127.0.0.1 -p 5333-p 5354时,我得到的响应是

; <<>> DiG 9.10.3-P4-Debian <<>> pi-hole.net @127.0.0.1 -p 5354
;; global options: +cmd
;; connection timed out; no servers could be reached

我认为这可能与pihole容器无法通过本地主机与Unbound容器进行通信有关,因此更新了我的docker-compose以尝试使用netowkr桥进行更正。但是之后,无论我尝试使用哪个端口,我仍然会遇到相同的错误。我是新来的Docker和Unbound,所以这是深入了解的地方!我的docker-compose.yml和unbound.conf在下面。

docker-compose.yml

version: "3.7"

services:
  unbound:
    cap_add:
      - NET_ADMIN
      - SYS_ADMIN
    container_name: unbound
    image: masnathan/unbound-arm
    ports:
      - 8953:8953/tcp
      - 5354:53/udp
      - 5354:53/tcp
      - 5333:5333/udp
      - 5333:5333/tcp
    volumes:
      - ./config/unbound.conf:/etc/unbound/unbound.conf
      - ./config/root.hints:/var/unbound/etc/root.hints
    restart: always
    networks:
      - unbound-pihole
  pihole:
    cap_add:
      - NET_ADMIN
      - SYS_ADMIN
    container_name: pihole
    image: pihole/pihole:latest
    ports:
      - 53:53/udp
      - 53:53/tcp
      - 67:67/udp
      - 80:80
      - 443:443
    volumes:
      - ./config/pihole/:/etc/pihole/
    environment:
      - ServerIP=10.0.0.20
      - TZ=UTC
      - WEBPASSWORD=random
      - DNS1=127.0.0.1#5333
      - DNS2=no
    restart: always 
    networks:
      - unbound-pihole

networks:
  unbound-pihole:
    driver: bridge

unbound.conf

server:
# If no logfile is specified, syslog is used
# logfile: "/var/log/unbound/unbound.log"
verbosity: 0

port: 5333
do-ip4: yes
do-udp: yes
do-tcp: yes

# May be set to yes if you have IPv6 connectivity
do-ip6: no

# Use this only when you downloaded the list of primary root servers!
root-hints: "/var/unbound/etc/root.hints"

# Trust glue only if it is within the servers authority
harden-glue: yes

# Require DNSSEC data for trust-anchored zones, if such data is absent, the zone becomes BOGUS
harden-dnssec-stripped: yes

# Don't use Capitalization randomization as it known to cause DNSSEC issues sometimes
# see https://discourse.pi-hole.net/t/unbound-stubby-or-dnscrypt-proxy/9378 for further details
use-caps-for-id: no

# Reduce EDNS reassembly buffer size.
# Suggested by the unbound man page to reduce fragmentation reassembly problems
edns-buffer-size: 1472

# TTL bounds for cache
cache-min-ttl: 3600
cache-max-ttl: 86400

# Perform prefetching of close to expired message cache entries
# This only applies to domains that have been frequently queried
prefetch: yes

# One thread should be sufficient, can be increased on beefy machines
num-threads: 1

# Ensure kernel buffer is large enough to not loose messages in traffic spikes
so-rcvbuf: 1m

# Ensure privacy of local IP ranges
private-address: 192.168.0.0/16
private-address: 169.254.0.0/16
private-address: 172.16.0.0/12
private-address: 10.0.0.0/8
private-address: fd00::/8
private-address: fe80::/10

谢谢!

1 个答案:

答案 0 :(得分:0)

access-control section下的文档https://nlnetlabs.nl/documentation/unbound/unbound.conf/

  By default only localhost is allowed, the rest is refused.   The
  is  refused, because that is protocol-friendly. The DNS
  protocol is not designed to handle dropped packets due  to  pol-
  icy,  and  dropping  may  result in (possibly excessive) retried
  queries.

默认情况下,未绑定的服务器仅侦听来自localhost的连接。在这种情况下,可以允许从未绑定运行的Docker容器内部接受对DNS服务器的请求。

因此,要允许docker-compose中的未绑定解析DNS,请将以下内容添加到unbound.conf

server:
   access-control: 0.0.0.0/0 allow