diff --git a/Config/DNS/Dockerfile b/Config/DNS/Dockerfile index a38d013..2b6879d 100644 --- a/Config/DNS/Dockerfile +++ b/Config/DNS/Dockerfile @@ -6,15 +6,16 @@ FROM debian +# Remove Existing Config +RUN rm -rfv /etc/{hosts,resolv.conf,dnsmasq.conf} + # Install Dependencies RUN apt update && apt install -y dnsmasq -# Remove Existing Config -RUN systemctl stop dnsmasq -RUN rm -rfv /etc/{hosts,resolv.conf,dnsmasq.conf} - # Copy Configuration Files -COPY ./config/{hosts,resolv.conf,dnsmasq.conf} /etc/ +COPY ./config/hosts /etc/ +COPY ./config/resolv.conf /etc/ +COPY ./config/dnsmasq.conf /etc/ -# Start Container -CMD systemctl restart dnsmasq +## Reload Service +RUN service dnsmasq restart diff --git a/Config/DNS/docker-compose.yml b/Config/DNS/docker-compose.yml index 01f18ae..f30ea37 100644 --- a/Config/DNS/docker-compose.yml +++ b/Config/DNS/docker-compose.yml @@ -10,6 +10,14 @@ version: '3' services: app: build: ./ - restart: always + restart: on-failure ports: - "53:53" + command: | + /bin/sh -c ' + while : + do + sleep 8h & wait $${!} + service dnsmasq restart + done + ' diff --git a/Config/DNS/run.sh b/Config/DNS/run.sh new file mode 100755 index 0000000..338d724 --- /dev/null +++ b/Config/DNS/run.sh @@ -0,0 +1,47 @@ +# 2023-07-29 +# Config/DNS/run.sh +# Fix common issues when trying to run this container. + +function stop-service { + service="" + if [[ -n $1 ]]; then + service=$1 + else + echo "ERROR: A parameter was not provided for stop-service, aborting." + exit 1 + fi + if [[ -n $2 ]]; then + echo "ERROR: A second parameter to stop-service is not expected, aborting." + exit 1 + fi + systemctl disable --now $service && + echo "$service stopped successfully!" || + echo "$service was not found, no problem." +} + +echo -e "\n*** Turn off any local DNS programs ***" +# These programs use port 53 but this container needs to be able to listen on it. +stop-service systemd-resolved +stop-service dnsmasq + +echo -e "\n*** Create a working DNS file ***" +# Allows the domains needed during the docker pull/build to be accessed. +if [[ ! -e /etc/resolv.conf.save ]]; then + # Save the existing file if a backup does not already exist. + mv /etc/resolv.conf /etc/resolv.conf.save +fi +echo "nameserver 1.1.1.1" > /etc/resolv.conf + +echo -e "\n*** Start the docker container ***" +docker compose down +docker compose build +docker compose up -d + +echo -e "\n*** Now use the local process for DNS ***\n/etc/resolv.conf:" +echo "nameserver 127.0.0.1" > /etc/resolv.conf +echo "nameserver 127.0.1.1" >> /etc/resolv.conf +cat /etc/resolv.conf + +# Finish +echo " " +exit 0 diff --git a/Config/DNS/undo.sh b/Config/DNS/undo.sh new file mode 100755 index 0000000..d922e1a --- /dev/null +++ b/Config/DNS/undo.sh @@ -0,0 +1,44 @@ +# 2023-07-29 +# Config/DNS/undo.sh +# Easy way to stop using this container. + +function start-service { + service="" + if [[ -n $1 ]]; then + service=$1 + else + echo "ERROR: A parameter was not provided for start-service, aborting." + exit 1 + fi + if [[ -n $2 ]]; then + echo "ERROR: A second parameter to start-service is not expected, aborting." + exit 1 + fi + systemctl enable --now $service && + echo "$service started successfully!" || + echo "$service was not found, no problem." +} + +echo -e "\n*** Stop the docker container ***" +docker compose down + +echo -en "\n*** Restore the DNS file " +if [[ -e /etc/resolv.conf.save ]]; then + echo "from backup ***" + cp /etc/resolv.conf.save /etc/resolv.conf +else + echo "with Cloudflare ***" + echo "nameserver 1.1.1.1" > /etc/resolv.conf + echo "nameserver 1.0.0.1" >> /etc/resolv.conf + echo "options rotate" >> /etc/resolv.conf +fi +echo "/etc/resolv.conf:" +cat /etc/resolv.conf + +echo -e "\n*** Turn on any local DNS programs ***" +start-service systemd-resolved +start-service dnsmasq + +# Finish +echo " " +exit 0