Skip to content

Instantly share code, notes, and snippets.

@JasonGhent
Last active October 22, 2017 02:36
Show Gist options
  • Save JasonGhent/5032d9ee1ff5a99304a917316d2a5be8 to your computer and use it in GitHub Desktop.
Save JasonGhent/5032d9ee1ff5a99304a917316d2a5be8 to your computer and use it in GitHub Desktop.
pi-hole docker setup
#!/bin/bash
# Run on raspberry pi
# source: https://github.com/diginc/docker-pi-hole
IP_LOOKUP="$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')" # May not work for VPN / tun0
IPv6_LOOKUP="$(ip -6 route get 2001:4860:4860::8888 | awk '{ print $10; exit }')" # May not work for VPN / tun0
IP="${IP:-$IP_LOOKUP}" # use $IP, if set, otherwise IP_LOOKUP
IPv6="${IPv6:-$IPv6_LOOKUP}" # use $IPv6, if set, otherwise IP_LOOKUP
DOCKER_CONFIGS="$(pwd)" # Default of directory you run this from, update to where ever.
echo "IP: ${IP} - IPv6: ${IPv6}"
# Default ports + daemonized docker container
docker run -d \
--name pihole \
-p 53:53/tcp -p 53:53/udp -p 80:80 \
-v "${DOCKER_CONFIGS}/pihole/:/etc/pihole/" \
-v "${DOCKER_CONFIGS}/dnsmasq.d/:/etc/dnsmasq.d/" \
-e ServerIP="${IP:-$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')}" \
-e ServerIPv6="${IPv6:-$(ip -6 route get 2001:4860:4860::8888 | awk '{ print $10; exit }')}" \
--restart=always \
diginc/pi-hole:arm
# Save this password!
docker logs pihole 2> /dev/null | grep 'password:'
# Update pihole
docker exec pihole pihole -up
echo "Update router's DHCP server's Static DNS 1 entry to pihole IP (${IP:-$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')}) then open ${IP:-$(ip route get 8.8.8.8 | awk '{ print $NF; exit }')}/admin in a web browser"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment