Question: Docker'd pi-hole DHCP not working!

Expected Behaviour:

Hand out ip addresses to wireless devices correctly and function like a DHCP server should.

Actual Behaviour:

DHCP server does not hand out ip-addresses.

Debug Token:

720ryvvjjw

Hi everyone!

Today I installed pi-hole in a docker and got it functioning correctly. Everything is working and I can successfully block ads. I installed pi-hole mainly because of its DHCP server. My ISP recently sent us a free replacement for our old, crappy modem/router combo and it's been functioning poorly. The thing is, my ISP's default DNS-servers are weird and slow and their new modem/router combo does not allow changing this. Certain URLS are blocked (cannot access Nintendo Online, works fine through mobile hotspot on my phone). I wanted to hand out IP addresses via the DHCP-function of the pi-hole, so that I could use proper DNS-servers instead of the ISPs ones. I have disabled DHCP on the ISP-sent router and enabled it on the pi-hole server afterwards, but I am unable to visit any un-cached sites on wireless devices. My Desktop that is hard-wired and has a static ip works fine. The pi-hole also has a static ip.

Any ideas? Help is much appreciated!

Kind Regards,
David

What is your docker run command?

The easiest way to get DHCP to work is remove the ports (-p #:#) and add --net=host to get the container onto the same network as your docker host which enables it to pass out IPs to that network. Without --net=host your container is isolated into a private docker network.

1 Like
#!/bin/bash -e
# Lookups may not work for VPN / tun0
IP_LOOKUP="$(ip route get 8.8.8.8 | awk '{for(i=1;i<=NF;i++) if ($i=="src") 
print $(i+1)}')"
IPv6_LOOKUP="$(ip -6 route get 2001:4860:4860::8888 | awk '{for(i=1;i<=NF;i++) 
if ($i=="src") print $(i+1)}')"

# Just hard code these to your docker server's LAN IP if lookups aren't working
IP="${IP:-$IP_LOOKUP}"  # use $IP, if set, otherwise IP_LOOKUP
IPv6="${IPv6:-$IPv6_LOOKUP}"  # use $IPv6, if set, otherwise IP_LOOKUP

# Default of directory you run this from, update to where ever.
DOCKER_CONFIGS="$(pwd)"

echo -e "### Make sure your IPs are correct, hard code ServerIP ENV VARs if 
necessary\nIP: ${IP}\nIPv6: ${IPv6}"

# Default ports + daemonized docker container
# Environment variables for docker can be defined in --env-file .env file
docker run -d \
    --name pihole \
    --env-file .env \
    -p 53:53/tcp -p 53:53/udp \
    -p 80:80 \
    -p 443:443 \
    --cap-add=NET_ADMIN \
    -v "${DOCKER_CONFIGS}/pihole/:/etc/pihole/" \
    -v "${DOCKER_CONFIGS}/dnsmasq.d/:/etc/dnsmasq.d/" \
    -e ServerIP="${IP}" \
    --restart=unless-stopped \
    --dns=127.0.0.1 --dns=1.1.1.1 \
    pihole/pihole:latest


printf 'Starting up pihole container '
for i in $(seq 1 20); do
    if [ "$(docker inspect -f "{{.State.Health.Status}}" pihole)" == "healthy" ];
        then
        printf ' OK'
        echo -e "\n$(docker logs pihole 2> /dev/null | grep 'password:') for 
your pi-hole: https://${IP}/admin/"
        exit 0
    else
        sleep 3
        printf '.'
    fi

    if [ $i -eq 20 ] ; then
        echo -e "\nTimed out waiting for Pi-hole start start, consult check your 
container logs for more info (\`docker logs pihole\`)"
        exit 1
    fi
done;

Changing to --net=host seems to have done the trick; I'm gonna test it out for a day but it seems like you fixed it! Thank you so much :).

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