From ae5a5afdc592968fb307257c11209d2c9f557f97 Mon Sep 17 00:00:00 2001 From: haxwithaxe Date: Wed, 9 Mar 2022 11:48:24 -0500 Subject: [PATCH 1/5] Added support for docker links (domain names) as DNS servers. Signed-off-by: haxwithaxe --- start.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index ef8813c..3ddf34d 100755 --- a/start.sh +++ b/start.sh @@ -127,9 +127,22 @@ if [ -n "${PIHOLE_DNS_}" ]; then change_setting "PIHOLE_DNS_$count" "$i" ((count=count+1)) ((valid_entries=valid_entries+1)) - else - echo "Invalid IP detected in PIHOLE_DNS_: ${i}" + continue fi + if [ -n "$(dig +short $i)" ]; then + # If the "address" is a domain (for example a docker link) then try to resolve it and add + # the result as a DNS server in setupVars.conf. + resolved_ip="$(dig +short $i | head -n 1)" + echo "Resolved ${i} from PIHOLE_DNS_ as: ${resolved_ip}" + if valid_ip "$resolved_ip" || valid_ip6 "$resolved_ip" ; then + change_setting "PIHOLE_DNS_$count" "$resolved_ip" + ((count=count+1)) + ((valid_entries=valid_entries+1)) + continue + fi + fi + # If the above tests fail then this is an invalid DNS server + echo "Invalid IP detected in PIHOLE_DNS_: ${i}" done if [ $valid_entries -eq 0 ]; then From e4a1abb5fbdc0ad5eb6dc7a68f7c4d014540ddb3 Mon Sep 17 00:00:00 2001 From: haxwithaxe Date: Sun, 13 Mar 2022 22:40:37 -0400 Subject: [PATCH 2/5] Added docker service name info to PIHOLE_DNS_ section. Signed-off-by: haxwithaxe --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2919829..3a60ee7 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ There are other environment variables if you want to customize various things in | Variable | Default | Value | Description | | -------- | ------- | ----- | ---------- | | `ADMIN_EMAIL` | unset | email address | Set an administrative contact address for the Block Page | -| `PIHOLE_DNS_` | `8.8.8.8;8.8.4.4` | IPs delimited by `;` | Upstream DNS server(s) for Pi-hole to forward queries to, seperated by a semicolon
(supports non-standard ports with `#[port number]`) e.g `127.0.0.1#5053;8.8.8.8;8.8.4.4` Note: The existence of this environment variable assumes this as the _sole_ management of upstream DNS. Upstream DNS added via the web interface will be overwritten on container restart/recreation | +| `PIHOLE_DNS_` | `8.8.8.8;8.8.4.4` | IPs delimited by `;` | Upstream DNS server(s) for Pi-hole to forward queries to, seperated by a semicolon
(supports non-standard ports with `#[port number]`) e.g `127.0.0.1#5053;8.8.8.8;8.8.4.4`
(supports [Docker service names and links](https://docs.docker.com/compose/networking/) instead of IPs) e.g `upstream0;upstream1` where `upstream0` and `upstream1` are the service names of or links to docker services
Note: The existence of this environment variable assumes this as the _sole_ management of upstream DNS. Upstream DNS added via the web interface will be overwritten on container restart/recreation | | `DNSSEC` | `false` | `<"true"\|"false">` | Enable DNSSEC support | | `DNS_BOGUS_PRIV` | `true` |`<"true"\|"false">`| Never forward reverse lookups for private ranges | | `DNS_FQDN_REQUIRED` | `true` | `<"true"\|"false">`| Never forward non-FQDNs | From 1c24b960480a14da1cce527390be78f72474a58d Mon Sep 17 00:00:00 2001 From: haxwithaxe Date: Sun, 13 Mar 2022 22:46:21 -0400 Subject: [PATCH 3/5] Fixed references to IP(s) to entry/entries in PIHOLE_DNS_ parsing block of start.sh. Signed-off-by: haxwithaxe --- start.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 3ddf34d..3304461 100755 --- a/start.sh +++ b/start.sh @@ -142,11 +142,11 @@ if [ -n "${PIHOLE_DNS_}" ]; then fi fi # If the above tests fail then this is an invalid DNS server - echo "Invalid IP detected in PIHOLE_DNS_: ${i}" + echo "Invalid entry detected in PIHOLE_DNS_: ${i}" done if [ $valid_entries -eq 0 ]; then - echo "No Valid IPs dectected in PIHOLE_DNS_. Aborting" + echo "No Valid entries dectected in PIHOLE_DNS_. Aborting" exit 1 fi else From 06569a5bcde33af81eb4502726e41afee68c99bc Mon Sep 17 00:00:00 2001 From: haxwithaxe Date: Mon, 14 Mar 2022 18:02:41 -0400 Subject: [PATCH 4/5] Handles docker service names with ports. Signed-off-by: haxwithaxe --- start.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/start.sh b/start.sh index 3304461..f67fbf7 100755 --- a/start.sh +++ b/start.sh @@ -129,10 +129,13 @@ if [ -n "${PIHOLE_DNS_}" ]; then ((valid_entries=valid_entries+1)) continue fi - if [ -n "$(dig +short $i)" ]; then + if [ -n "$(dig +short ${i//#*/})" ]; then # If the "address" is a domain (for example a docker link) then try to resolve it and add # the result as a DNS server in setupVars.conf. - resolved_ip="$(dig +short $i | head -n 1)" + resolved_ip="$(dig +short ${i//#*/} | head -n 1)" + if [ -n "${i//*#/}" ]; then + resolved_ip="${resolved_ip}#${i//*#/}" + fi echo "Resolved ${i} from PIHOLE_DNS_ as: ${resolved_ip}" if valid_ip "$resolved_ip" || valid_ip6 "$resolved_ip" ; then change_setting "PIHOLE_DNS_$count" "$resolved_ip" From fb112ce1bfc10ea36049e432b56d30bd60a26fe7 Mon Sep 17 00:00:00 2001 From: haxwithaxe Date: Mon, 14 Mar 2022 18:20:19 -0400 Subject: [PATCH 5/5] Handles docker service names with and without ports. Signed-off-by: haxwithaxe --- start.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start.sh b/start.sh index f67fbf7..d0b44c1 100755 --- a/start.sh +++ b/start.sh @@ -133,7 +133,7 @@ if [ -n "${PIHOLE_DNS_}" ]; then # If the "address" is a domain (for example a docker link) then try to resolve it and add # the result as a DNS server in setupVars.conf. resolved_ip="$(dig +short ${i//#*/} | head -n 1)" - if [ -n "${i//*#/}" ]; then + if [ -n "${i//*#/}" ] && [ "${i//*#/}" != "${i//#*/}" ]; then resolved_ip="${resolved_ip}#${i//*#/}" fi echo "Resolved ${i} from PIHOLE_DNS_ as: ${resolved_ip}"