Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chosen upstream DNS servers not saved #604

Closed
2 tasks done
JaneX8 opened this issue Apr 27, 2020 · 25 comments
Closed
2 tasks done

Chosen upstream DNS servers not saved #604

JaneX8 opened this issue Apr 27, 2020 · 25 comments

Comments

@JaneX8
Copy link

JaneX8 commented Apr 27, 2020

In raising this issue, I confirm the following:

How familiar are you with the the source code relevant to this issue?:
1


Expected behaviour:

1: Change the Upstream DNS on the /admin/settings.php?tab=dns page. When docker was restarted or recreated (with persistent volume mounted) the chosen Upstream Servers in the list (left side) were not saved and back at Google DNS. I switched them several times to Cloudflare, saved. After a restart of container it was back at Google.

Actual behaviour:

Selection not saved.

Troubleshooting undertaken, and/or other relevant information:

Tried several Docker container restarts and recreated. Did not work. I fixed it now by setting the CloudFlare DNS IPs as a custom DNS server on the right side.

@dschaper dschaper transferred this issue from pi-hole/pi-hole Apr 27, 2020
@neutralalice
Copy link

neutralalice commented Apr 27, 2020

It's not very clear in the documentation, but you need to set it as an environment variable. Default is set to google on container creation. Change the environment to the servers you would like to use before creating the container.

Example:

services:
  pihole: 
    dns:
      - "127.0.0.1" # this tells the container what dns to use, not pihole
      - "9.9.9.9" # this tells the container what dns to use, not pihole
    environment:
      - TZ=America/Los_Angeles
      - DNS1=9.9.9.9 #this will edit the pihole dns upstream server to be quad 9 default 
      - DNS2=149.112.112.112 #this will edit the dns upstream server to be quad 9 default 

@ahuffman
Copy link
Contributor

ahuffman commented Apr 30, 2020

It would save if you've mounted persistent storage to /etc/pihole when launching the container. Also any customizations to the dnsmasq configs in /etc/dnsmasq.d would require a persistent volume to persist settings beyond a container relaunch.

@neutralalice
Copy link

It would save if you've mounted persistent storage to /etc/pihole when launching the container. Also any customizations to the dnsmasq configs in /etc/dnsmasq.d would require a persistent volume to persist settings beyond a container relaunch.

I found that even with persistant storage I had to set the environment variable, otherwise it would reset this specific part. All other changes would remain on container relaunch

    volumes: 
      - "etc-pihole:/etc/pihole"
      - "etc-dnsmasq.d:/etc/dnsmasq.d" 
volumes: 
  etc-dnsmasq.d: ~
  etc-pihole: ~

@casperklein
Copy link
Contributor

casperklein commented May 15, 2020

I found out, that configuring DNS servers in addition to the two default Google DNS servers does work. But as soon as you remove the two Google ones, it defaults back to only two Google DNS.

@Haarolean
Copy link

Happens to me as well.
I had my cloudflare dns replaced by google already twice (in 01-pihole.conf).
My docker-compose.yml file:

version: '3'
services:
  pihole:
...
    volumes:
       - '/opt/pihole/etc-pihole/:/etc/pihole/'
       - '/opt/pihole/etc-dnsmasq.d/:/etc/dnsmasq.d/'
    dns:
      - 127.0.0.1
      - 1.1.1.1

@cryptoluks
Copy link

Happens to me as well.
I had my cloudflare dns replaced by google already twice (in 01-pihole.conf).
My docker-compose.yml file:

version: '3'
services:
  pihole:
...
    volumes:
       - '/opt/pihole/etc-pihole/:/etc/pihole/'
       - '/opt/pihole/etc-dnsmasq.d/:/etc/dnsmasq.d/'
    dns:
      - 127.0.0.1
      - 1.1.1.1

Did you try putting your desired DNS as ENVIRONMENT variables in docker-compose.yml? See here. For me this works fine.

@casperklein
Copy link
Contributor

@cryptoluks That works. However it's only a workaround and no final solution.

@Haarolean
Copy link

Haarolean commented May 25, 2020 via email

@Knapoc
Copy link

Knapoc commented May 29, 2020

the thing is the dnsmasq config file is overwritten at container start since the following function in bash_functions.sh seems to fail:

setup_dnsmasq_config_if_missing() {
    # When fresh empty directory volumes are used we miss this file
    if [ ! -f /etc/dnsmasq.d/01-pihole.conf ] ; then
        cp /etc/.pihole/advanced/01-pihole.conf /etc/dnsmasq.d/
    fi;
}

@diginc could you provide some information?

@Knapoc
Copy link

Knapoc commented May 29, 2020

after endless digging I think I found the root cause:

  1. container start calls start.sh
  2. start.sh imports bash_functions.sh
  3. start.sh calls the prepare_configs function.
  4. prepare_configs calls installConfigs from pihole's basic-install.sh
  5. installConfigs calls version_check_dnsmasq which replaces /etc/dnsmasq/01-dnsmasq.conf

so the function setup_dnsmasq_config_if_missing is actually pointless as of now.

@ahuffman
Copy link
Contributor

Have you tried building the container off of the "dev" branch? #608 has been merged recently and may correct the problem.

@Knapoc
Copy link

Knapoc commented May 29, 2020

No I didn't but judging by the changes, this "only" fixes the issue for configurations done in setupVars.conf. Personally I have more interest in modifying dnsmasq options which cannot be set in setupVars (especially cache-size=0 and log-queries=extra).

Like a mentioned in a previous post the function setup_dnsmasq_config_if_missing in bash_functions.sh is completely pointless, since the dnsmasq-config is overwritten by pi-hole installer script anyway.

@fire1ce
Copy link

fire1ce commented Jun 2, 2020

Hey devs, this should be fixed. All the config files should be persistent. Updating docker image should not change my config files.
My setup uses cloudflared container. with custom port on the same host.
setupVars.conf config should stay pressistent

@PromoFaux
Copy link
Member

setupVars.conf config should stay pressistent

Does it not if you mount it as a volume? I have my entire /etc/pihole directory mounted to the host machine and don't see my setupVars.conf being overwritten on container upgrade.

@fire1ce
Copy link

fire1ce commented Jun 2, 2020

setupVars.conf config should stay pressistent

Does it not if you mount it as a volume? I have my entire /etc/pihole directory mounted to the host machine and don't see my setupVars.conf being overwritten on container upgrade.

tested it few time with mounted volume, every time the container is created it executes "touch" command and rewrites it.
I've tried to stop the rewrites with "chattet +i" flag, but since the touch command failed with "permission denied" creation of the container stopped with error.

@PromoFaux
Copy link
Member

Spoke to soon, yes I can see this now. I guess I've just never paid any close attention to it

That said, I have the DNS1/2 ENV vars set in my docker-compose.yml. This may be intended behaviour at the moment.. However, paging @diginc to weigh in here.

@fire1ce
Copy link

fire1ce commented Jun 2, 2020

Spoke to soon, yes I can see this now. I guess I've just never paid any close attention to it

That said, I have the DNS1/2 ENV vars set in my docker-compose.yml. This may be intended behaviour at the moment.. However, paging @diginc to weigh in here.

Personally using docker "run" and not "compose" which makes it even more complex coz i can't pass ENV of dns with port numbers, so my only options is to set it to 127.0.0.1 or not include DNS ENV at all, in both cases it will rewrite my config to google's dns.

Since i would like to run at least 3 containers (for real there are 18 at the same host right now): pihole, cloudflared, and watchtower for autoupdate of the containers the overwrites of config files prevent me from doing this.

@diginc
Copy link
Collaborator

diginc commented Jun 2, 2020

Test pihole/pihole:dev like @ahuffman mentioned please.

I wrote a test Sunday for this and it seemed setting custom DNS settings after startup + restarting preserved the DNS settings. This is a bash test not the usual python so it should be easier to run/reproduce issues. Worked on dev but let me know if I missed some element of how to reproduce the problem.

https://github.com/pi-hole/docker-pi-hole/pull/631/files#diff-c2cb325b583f5a066d29f58edb4f51e3

@fire1ce
Copy link

fire1ce commented Jun 2, 2020

Test pihole/pihole:dev like @ahuffman mentioned please.

I wrote a test Sunday for this and it seemed setting custom DNS settings after startup + restarting preserved the DNS settings. This is a bash test not the usual python so it should be easier to run/reproduce issues. Worked on dev but let me know if I missed some element of how to reproduce the problem.

https://github.com/pi-hole/docker-pi-hole/pull/631/files#diff-c2cb325b583f5a066d29f58edb4f51e3

Hey adam!
let's break the issue down.

  • Custom upstream DNS pressits at docker restart (that's great).
  • Updating a docker container to newer image process always deletes the current container, pulls new image, creating new updated container with the same params from current container.
    Basically it runs the same "docker run" command with all it's params from the first time you have run the container.
    To make it simpler it's the same as running docker stop <ID>, docker rm <ID>, docker run.... PARMS. Since we have an option to pass a folder mount from the host to the container for it's configuration files the desired result should be when creating new container with the same mount configuration is that all of the configuration files will be the same for the new container.

To reproduce the issue:

  • Create a pihole container with persistent folder from host to container
  • Edit custom dns at webui
  • Delete the container
  • Create the same container with the same params (exactly the same command as first time).
    This will change the upstream dns to google's and rewrite the setupVars.conf, 01-pihole.conf.

@diginc
Copy link
Collaborator

diginc commented Jun 2, 2020

022b039

Look right? Seems to pass using :dev thanks to #608 / @ahuffman

@fire1ce
Copy link

fire1ce commented Jun 3, 2020

022b039

Look right? Seems to pass using :dev thanks to #608 / @ahuffman

Hey diginc, we still have problem with the
I've just pulled the latest pihole/pihole:dev
ran the container, changed to custom dns
removed the container
ran it again
setupVars.conf was overriten to google's dns.

commands:
docker pull pihole/pihole:dev

docker run \                                                                                                                     130 ↵
-d \
--name pihole \
--hostname pi.hole \
--restart=unless-stopped \
-p 53:53/tcp -p 53:53/udp \
-p 11511:80 \
-p 11512:443 \
-v /volume1/docker/pihole:/etc/pihole/ \
-v /volume1/docker/pihole/dnsmasq.d:/etc/dnsmasq.d/ \
-e VIRTUAL_HOST="pi.hole" \
-e PROXY_LOCATION="pi.hole" \
--dns=127.0.0.1 \
-e ServerIP="127.0.0.1" \
-e PUID=1000 \
-e PGID=1000 \
-e TZ=Asia/Jerusalem \
pihole/pihole:dev
cat setupVars.conf
BLOCKING_ENABLED=true
WEBPASSWORD=04f6c5873d03496da5b22f9ebc2d63cdbb124521ea768686727597e887479413
QUERY_LOGGING=true
INSTALL_WEB_SERVER=true
INSTALL_WEB_INTERFACE=true
LIGHTTPD_ENABLED=
IPV4_ADDRESS=127.0.0.1
IPV6_ADDRESS=
PIHOLE_INTERFACE=eth0
DNSMASQ_LISTENING=single
PIHOLE_DNS_1=127.0.0.1#5054
DNS_FQDN_REQUIRED=false
DNS_BOGUS_PRIV=false
DNSSEC=false
CONDITIONAL_FORWARDING=false

docker stop pihole && docker rm pihole

docker run \
-d \
--name pihole \
--hostname pi.hole \
--restart=unless-stopped \
-p 53:53/tcp -p 53:53/udp \
-p 11511:80 \
-p 11512:443 \
-v /volume1/docker/pihole:/etc/pihole/ \
-v /volume1/docker/pihole/dnsmasq.d:/etc/dnsmasq.d/ \
-e VIRTUAL_HOST="pi.hole" \
-e PROXY_LOCATION="pi.hole" \
-e ServerIP="127.0.0.1" \
-e PUID=1000 \
-e PGID=1000 \
-e TZ=Asia/Jerusalem \
pihole/pihole:dev
cat setupVars.conf
BLOCKING_ENABLED=true
WEBPASSWORD=04f6c5873d03496da5b22f9ebc2d63cdbb124521ea768686727597e887479413
DNSMASQ_LISTENING=single
QUERY_LOGGING=true
INSTALL_WEB_SERVER=true
INSTALL_WEB_INTERFACE=true
LIGHTTPD_ENABLED=
IPV4_ADDRESS=127.0.0.1
IPV6_ADDRESS=
DNS_BOGUS_PRIV=
DNS_FQDN_REQUIRED=
DNSSEC=
CONDITIONAL_FORWARDING=
CONDITIONAL_FORWARDING_IP=
CONDITIONAL_FORWARDING_DOMAIN=
CONDITIONAL_FORWARDING_REVERSE=
PIHOLE_DNS_1=8.8.8.8
PIHOLE_DNS_2=8.8.4.4
PIHOLE_INTERFACE=eth0

@fire1ce
Copy link

fire1ce commented Jun 6, 2020

any news?

@mvdkleijn
Copy link

I am experiencing this issue as well... it is extremely annoying behaviour. :)

Basically when doing a docker-compose down, followed by an up, the setupVars.conf file is overwritten. All values are preserved except for DNS1 and DNS2... so DNS3 and DNS4 are left alone.

It would be nice if the content of setupVars.conf would be left alone during restart / recreation....

@ChrisBaker97
Copy link

To add on to this, if only DNS1 is specified in the environment in docker-compose.yaml, when the container is recreated, the custom DNS1 is set as the only primary, but DNS2 gets re-set as Google. In case anyone else wants just a single upstream custom DNS server, I did find that setting DNS2='' does the trick.

@PromoFaux
Copy link
Member

Closed in place of the pinned #720

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests