This is a follow up to Start: Support hostnames and domains in PIHOLE_DNS_ by networkException · Pull Request #816 · pi-hole/docker-pi-hole · GitHub #docker
Currently the docker configuration does not allow for a hostname or domain in the pihole dns configuration. Technically DNS servers are never domains but in some cases the ip of a domain might want to be used as the DNS server. In particular a docker-compose stack would benefit from this feature:
services:
pihole:
image: pihole/pihole
hostname: pihole
depends_on:
- dnscrypt
ports:
- 53:53/udp
environment:
PIHOLE_DNS_: dnscrypt
dnscrypt:
image: #...
By resolving the ip of "dnscrypt" on startup, pihole could now use the dnscrypt container as a DNS server.
DL6ER
October 24, 2021, 7:44am
2
@PromoFaux Could you check this out?
system
Closed
April 22, 2022, 7:45am
3
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
There is an upstream PR to dnsmasq
which would implement this feature
pi-hole:master
← pi-hole:new/resolve_server
opened 03:22PM - 03 Feb 22 UTC
In docker swarm and compose configurations, other containers are only reachable … via hostnames. It is not possible to assign IP addresses beforehand. Hence, the upstream server IP is not known at `dnsmasq` start when the upstream is part of the deployed configuration, e.g., a local `cloudflared` or `unbound` container.
So far, getting `dnsmasq` to run in such a case requires hacks that somehow try to determine the IP address before starting dnsmasq. An example for such a hack: https://github.com/tschaffter/docker-dnsmasq/blob/54b5d5d551746b6f1708fbf4a705e2de66c2eaee/docker-entrypoint.sh#L14-L23
This patch implements name resolution functionality for `server=...` by querying the system resolver for a hostname. It is only used when a user supplied something that is not a valid IP address (`dnsmasq` currently fails hard in this case) and can be omitted by a compile time flag (I think it's worthwhile to have it). I know my proposal does sound somewhat strange (resolving a DNS server name) but this is something that is somewhat frequently needed and currently only possible through external hacks.
1 Like
Sorry, I never saw this tag/topic!
However, this has actually been a part of the docker image since around March of this year:
pi-hole:dev
← haxwithaxe:support-docker-links-for-PIHOLE_DNS_dev
opened 06:46PM - 09 Mar 22 UTC
Added the ability to use docker service names or links in `PIHOLE_DNS_`.
## D… escription
In `start.sh` I added a check for valid domains to the block in the loop over `PIHOLE_DNS_`. The valid domains are resolved and the IP addresses are added to the configs in the same way as DNS servers specified as IPs. I also slightly rearranged the if block to avoid duplicating the warning about invalid servers.
## Motivation and Context
I have a setup that uses an unbound container to provide DoT. I'm trying to integrate this composition as a stack in a swarm and it would greatly simplify the configuration if docker service names could be used. It would also make the behavior of this image more idiomatic.
## How Has This Been Tested?
1. `ARCH=amd64 ./gh-actions-test.sh` 25 passed, 11 skipped
3. Using the docker-compose.yml (below) with `PIHOLE_DNS_` set to "unbound;1.2.3.4" I started the composition.
4. I logged in to the pi-hole admin UI and verified the IP of the unbound container was set as the first custom server and 1.2.3.4 was the second. Then I removed the etc-* directories created in the working directory.
5. I repeated this with just IPv4 addresses.
6. I repeated this with just IPv6 addresses. The parts related to my change worked, but this produced an unrelated pihole-FTL error that exists in `pihole/pihole:latest` as well.
7. I repeated this with just the docker link.
Except for the IPv6 only test the specified IPs or IPs of specified service names were shown as the custom DNS servers and no errors were apparent in the logs.
## Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
## Checklist:
- [x] My code follows the code style of this project. (I tried to be consistent with the surrounding code)
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
```
version: "2"
services:
pihole:
container_name: pihole
image: pihole:support-docker-links-for-PIHOLE_DNS_dev-amd64-buster
ports:
- "53:53/tcp"
- "53:53/udp"
#- "67:67/udp" # Required for DHCP
- "80:80/tcp"
environment:
TZ: "America/New_York"
PIHOLE_DNS_: "unbound;1.2.3.4"
volumes:
- "./etc-pihole:/etc/pihole"
- "./etc-dnsmasq.d:/etc/dnsmasq.d"
#cap_add: # Required for DHCP
# - NET_ADMIN
restart: unless-stopped
unbound:
image: haxwithaxe/unbound-dot:latest
```
Though maybe with this new code in FTL/dnsmasq, we can change that up a little
Edit:
Ah, yes, @networkException is aware - from the linked PR:
Thanks a lot for implementing this! I can finally decomission my patched start.sh then