DNS Container and docker compose

This commit is contained in:
Eduardo Silva 2024-04-29 15:26:30 -03:00
parent da1513e560
commit aefd3f698b
18 changed files with 175 additions and 20 deletions

View file

@ -0,0 +1,13 @@
FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y dnsmasq nano inotify-tools psmisc && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

View file

@ -0,0 +1,40 @@
#!/bin/bash
CONFIG_FILE="/etc/dnsmasq/wireguard_webadmin_dns.conf"
DEFAULT_CONFIG_CONTENT="
no-dhcp-interface=
server=1.1.1.1
server=1.0.0.1
listen-address=0.0.0.0
bind-interfaces
"
create_default_config() {
if [ ! -f "$CONFIG_FILE" ]; then
echo "Config file not found, creating a new one..."
echo "$DEFAULT_CONFIG_CONTENT" > "$CONFIG_FILE"
fi
}
start_dnsmasq() {
dnsmasq -C "$CONFIG_FILE" &
while inotifywait -e modify "$CONFIG_FILE"; do
echo "Configuration changed, reloading dnsmasq..."
pkill dnsmasq
sleep 5
dnsmasq -C "$CONFIG_FILE" &
done
}
handle_sigint() {
echo "SIGINT received. Stopping inotifywait and dnsmasq..."
pkill inotifywait
pkill dnsmasq
exit 0
}
trap handle_sigint SIGINT
create_default_config
start_dnsmasq