# Support hostnames and domains in PIHOLE\_DNS\_

**URL:** <https://discourse.pi-hole.net/t/support-hostnames-and-domains-in-pihole-dns/50572>\
**Category:** Implemented\
**Created:** [October 23, 2021, 8:37pm UTC](https://discourse.pi-hole.net/t/support-hostnames-and-domains-in-pihole-dns/50572 "2021-10-23T20:37:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![networkException](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/networkexception/32/27888_2.png) [@networkException](https://discourse.pi-hole.net/u/networkException)\
**Post date:** [October 23, 2021, 8:37pm UTC](https://discourse.pi-hole.net/t/support-hostnames-and-domains-in-pihole-dns/50572/1 "2021-10-23T20:37:44Z")

</div>

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](https://github.com/pi-hole/docker-pi-hole/pull/816) #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:

```yml
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.

---

<div class="post-metadata">

**Author:** ![DL6ER](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/dl6er/32/281_2.png) [@DL6ER](https://discourse.pi-hole.net/u/DL6ER)\
**Post date:** [October 24, 2021, 7:44am UTC](https://discourse.pi-hole.net/t/support-hostnames-and-domains-in-pihole-dns/50572/2 "2021-10-24T07:44:14Z")

</div>

@PromoFaux Could you check this out?

---

<div class="post-metadata">

**Author:** ![system](https://discourse.pi-hole.net/uploads/default/original/3X/7/c/7c8792f649eeb921c5d2b4c41564ffa873d9a2b8.png) [@system](https://discourse.pi-hole.net/u/system)\
**Post date:** [April 22, 2022, 7:45am UTC](https://discourse.pi-hole.net/t/support-hostnames-and-domains-in-pihole-dns/50572/3 "2022-04-22T07:45:11Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![yubiuser](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/yubiuser/32/12100_2.png) [@yubiuser](https://discourse.pi-hole.net/u/yubiuser)\
**Post date:** [May 31, 2022, 9:18pm UTC](https://discourse.pi-hole.net/t/support-hostnames-and-domains-in-pihole-dns/50572/4 "2022-05-31T21:18:34Z")

</div>



---

<div class="post-metadata">

**Author:** ![yubiuser](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/yubiuser/32/12100_2.png) [@yubiuser](https://discourse.pi-hole.net/u/yubiuser)\
**Post date:** [May 31, 2022, 9:19pm UTC](https://discourse.pi-hole.net/t/support-hostnames-and-domains-in-pihole-dns/50572/5 "2022-05-31T21:19:39Z")

</div>

There is an upstream PR to `dnsmasq` which would implement this feature

> <https://github.com/pi-hole/dnsmasq/pull/9>
>
> 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.

---

<div class="post-metadata">

**Author:** ![yubiuser](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/yubiuser/32/12100_2.png) [@yubiuser](https://discourse.pi-hole.net/u/yubiuser)\
**Post date:** [November 14, 2022, 10:09pm UTC](https://discourse.pi-hole.net/t/support-hostnames-and-domains-in-pihole-dns/50572/6 "2022-11-14T22:09:50Z")

</div>

This has been part of

> <https://github.com/pi-hole/FTL/pull/1469>
>
> \*\*By submitting this pull request, I confirm the following:\*\*
> 
> \- \[X\] I have re…ad and understood the \[contributors guide\](https://github.com/pi-hole/pi-hole/blob/master/CONTRIBUTING.md).
> \- \[X\] I have checked that \[another pull request\](https://github.com/pi-hole/FTL/pulls) for this purpose does not exist.
> \- \[X\] I have considered, and confirmed that this submission will be valuable to others.
> \- \[X\] I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
> \- \[X\] I give this submission freely, and claim no ownership to its content.
> 
> \*\*How familiar are you with the codebase?:\*\* 
> 
> \## 10
> 
> \---
> 
> Updates the embedded \`dnsmasq\` to the next tagged version of \`dnsmasq\`. Highlights compared to the most recent version of \`dnsmasq\` (v2.87) released in FTL v5.18:
> 
> \*\*New options/features\*\*
> \- \*\*Allow domain names as well is IP addresses in \`server\` options\*\* - this will be especially helpful in situations where upstream destinations are primarily reachable by hostname (think of DHCP networks and \`docker compose\`, etc.) (\*\*\*Pi-hole patch\*\*\*)
> \- \`use-stale-cache\` - when set, \*\*if a DNS name exists in the cache, but its time-to-live has expired, \`dnsmasq\` will return the data anyway\*\* and attempts itself to refresh the data with an upstream query after returning the stale data.
> 
> Advantages:
> - This can improve speed as we can always reply immediately to known queries, even when cached content has expired, instead of having to wait for upstream replies to arrive.
> 
> Disadvantages:
> - In certain edge-cases, these out-of-data replies can lead to (intermittent) incorrect behavior on websites.
> - There is no way to inform a downstream client that an answer we provided before was wrong. The client may cache wrong data for a long time until it re-sends a query to get the updated information.
> - It comes at the expense of sometimes returning out-of-date replies and less efficient cache utilization, since old data cannot be flushed when its TTL expires. The cache becomes strictly least-recently-used.
> 
> \- New \`fast-dns-retry\` option - \*\*gives dnsmasq the ability to originate retries for upstream DNS queries itself\*\*, rather than relying on the downstream client. This is most useful when doing DNSSEC over unreliable upstream network. Retries are generated when no reply was received for 1 second. Retries are repeated with exponential backoff until we give up after 10 seconds. Both values are configurable with millisecond accuracy.
> 
> Advantages:
> - Queries without replies to will be retried earlier resulting in significantly reduced reply times on flaky upstream connections. Note that this does only apply to the connection between the Pi-hole and the upstream destination. It does not mean any improvement on unreliable connections between your Pi-hole and clients (like over a weak WiFi signal or an unreliable VPN connection).
> 
> Drawbacks:
> - It comes with hard-to-quantify extra costs in memory usage and network bandwidth.
> - It will only be useful if your Internet connectivity is \*really\* bad. You should try out any other possible remedy before relying on this one.
> 
> \- New \`port-limit=\<#ports\>\` option - by default, when sending a query via random ports to multiple upstream servers or retrying a query dnsmasq will use a single random port for all the tries/retries.
> 
> Advantages:
> - This option allows a larger number of ports to be used, which can increase robustness in certain network configurations.
> 
> Disadvantages:
> 
> - Note that increasing this to more than two or three can have security and resource implications and should only be done with understanding of those (the requesting port is part of the "secret").
> 
> \- New \`no-round-robin\` option - suppresses round-robin ordering of DNS records and ensures answers are always served in the same order.
> 
> \- Enhance \`hostsdir\` to remove outdated entries on changes. Before, this required a full \`dnsmasq\` restart (\*\*\*Pi-hole patch\*\*\*)
> \- Improve \`hostsdir\` logging to log the HOSTS file used for generating a local reply (\*\*\*Pi-hole patch\*\*\*)
> 
> \*\*Bugfixes\*\*
> 
> \- Fix bug in \`dynamic-host\` when interface has \`/16\` address (\*\*\*Pi-hole patch\*\*\*)
> \- Fix in DHCPv4 \`rapid-commit\` - If a host had an old lease for a different address, the rapid-commit appeared to work, but the old lease was not removed and the new lease was not recorded, so the client and server had conflicting state, leading to problems later.

and is released with

> **[Release v5.19 · pi-hole/FTL](https://github.com/pi-hole/FTL/releases/tag/v5.19)**
>
> What's Changed
> 
> Fix comment on gravity-db.c by @rdwebdesign in #1456
> Fix compatibility with gcc 12.2.0 by @DL6ER in #1465
> Improve shared memory protection by @DL6ER in #1464
> Remove repo specific is...

---

<div class="post-metadata">

**Author:** ![yubiuser](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/yubiuser/32/12100_2.png) [@yubiuser](https://discourse.pi-hole.net/u/yubiuser)\
**Post date:** [November 14, 2022, 10:10pm UTC](https://discourse.pi-hole.net/t/support-hostnames-and-domains-in-pihole-dns/50572/7 "2022-11-14T22:10:09Z")

</div>



---

<div class="post-metadata">

**Author:** ![PromoFaux](https://discourse-cdn.pi-hole.net/user_avatar/discourse.pi-hole.net/promofaux/32/1545_2.png) [@PromoFaux](https://discourse.pi-hole.net/u/PromoFaux)\
**Post date:** [November 14, 2022, 10:41pm UTC](https://discourse.pi-hole.net/t/support-hostnames-and-domains-in-pihole-dns/50572/8 "2022-11-14T22:41:58Z")

</div>

> [@DL6ER](#):
>
> Could you check this out?

Sorry, I never saw this tag/topic!

However, this has actually been a part of the docker image since around March of this year:

> <https://github.com/pi-hole/docker-pi-hole/pull/1014>
>
> 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 😅
