cytopia / docker-bind

Bind (bind9) caching DNS server on Alpine or Debian with wild-card domain support [multi-arch]
http://devilbox.org/
MIT License
91 stars 50 forks source link

problem with reverse resolution and multiple EXTRA_HOSTS #16

Closed eleaner closed 2 years ago

eleaner commented 5 years ago

following the readme, I try to resolve two hosts like below

docker service create \
  --name bind-dns \
  -p 53:53/tcp \
  -p 53:53/udp \
  -e EXTRA_HOSTS='hetzner1=10.8.0.5=hetzner1,hetzner2=10.8.0.9=hetzner2' \
  cytopia/bind

and I get following log with error error - docker service fails

bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] Debug level: 1
bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] Using default DNS TTL time: 3600 sec
bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] Using default DNS Refresh time: 1200 sec
bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] Using default DNS Retry time: 180 sec
bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] Using default DNS Expiry time: 1209600 sec
bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] Using default DNS Max Cache time: 10800 sec
bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] Adding extra host: hetzner1 -> 10.8.0.5 (PTR: hetzner1)
bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] Adding extra host: hetzner2 -> 10.8.0.9 (PTR: hetzner2)
bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] DNSSEC Validation: no
bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] Adding custom DNS forwarder: 8.8.8.8,8.8.4.4
bind-dns.1.8wkm3glijglg@kimsufi1    | [INFO] Starting BIND 9.11.4
bind-dns.1.8wkm3glijglg@kimsufi1    | /etc/bind/devilbox-extra_hosts.hetzner2.conf:7: zone '0.8.10.in-addr.arpa': already exists previous definition: /etc/bind/devilbox-extra_hosts.hetzner1.conf:7

Everything is working fine with only one specified host. If I try to define EXTRA_HOST twice, the last one wins

science695 commented 5 years ago

Why are you including the dns name twice? It is intended to be a pair hostname=ipaddress,...

EXTRA_HOSTS=mywebserver.loc=172.16.238.1 https://devilbox.readthedocs.io/en/latest/advanced/add-custom-cname-records.html?highlight=extra%20hosts

and, to match that to your case:

-e EXTRA_HOSTS='hetzner1=10.8.0.5,hetzner2=10.8.0.9'

eleaner commented 5 years ago

Please see section 5. Adding reverse DNS: https://github.com/cytopia/docker-bind#extra_hosts The following extra host 'my.host' is added and will always point to whatever IP example.org resolves to. As well as adding reverse DNS from 192.168.0.1 to resolve to tld EXTRA_HOSTS='tld=192.168.0.1=tld'

my requirement is to resolve hetzner1 -> 10.8.0.5 as well as 10.8.0.5 -> hetzner1 and it works as long as I have only one entry

science695 commented 5 years ago

Oh, I'm sorry. It looks like the developer added a feature I didn't know about.

I can confirm this bug. I'm going to send some additional information to the developer to help speed this up.

@cytopia: eleaner has found a bug with multiple extra_hosts with reverse lookup.

If you do: EXTRA_HOSTS=test.loc=172.16.238.42=test.loc,test2.loc=172.16.238.43=test2.loc (as long as both ip addresses are in the same subnet)

The configuration it creates returns an error: /etc/bind/devilbox-extra_hosts.test2.loc.conf:7: zone '238.16.172.in-addr.arpa': already exists previous definition: /etc/bind/devilbox-extra_hosts.test.loc:7

This is caused by always adding in a zone for the subnet for every extra host with reverse: https://github.com/cytopia/docker-bind/blob/master/data/docker-entrypoint.sh#L248

I'm not sure what you were solving by adding that subnet zone, but you might want to track witch subnets you've added a zone and not add duplicate zones.

cytopia commented 5 years ago

Good catch. I will probably have to create multiple zones then

dimkasta commented 5 years ago

Since this is mostly intended for internal use, adding the reverse zone could be implicit for all cases? Just a thought

mboehm21 commented 4 years ago

Is there already a way to get the reverse-lookup working again? Is there also a way to round-robin load-balance with this dns-server?

Thanks for creating this really nice image, by the way.

cytopia commented 2 years ago

@eleaner @science695 @dimkasta @mboehm21

thanks for the issue. I have made a major rewrite which addresses the fix here: https://github.com/cytopia/docker-bind/pull/36