diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4c8eb4d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM alpine:edge + +RUN apk --no-cache add dnsmasq + +EXPOSE 53/udp +EXPOSE 67/udp +EXPOSE 68/udp + +RUN mkdir -p /etc/dnsmasq.d/config +COPY dns.conf /etc/dnsmasq.d/ && \ + dhcp-conf /etc/dnsmasq.d/ && \ + dhcp-reservations.conf /etc/dnsmasq.d/ && \ + hosts.local /etc/dnsmasq.d/ && \ + +COPY entrypoint.sh / + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/dhcp-reservations.conf b/dhcp-reservations.conf new file mode 100644 index 0000000..7fb1201 --- /dev/null +++ b/dhcp-reservations.conf @@ -0,0 +1,11 @@ +# file: dhcp-reservations.conf +# description: This file is for setting DHCP reservations (static DHCP entries) + +# Set DHCP Reservations Here +# Reservations follow the format below, and the IP address does not need to fall +# within one of the ranges you've defined in your dnsmasq.conf, it must only be +# valid for the specified network. +# +# dhcp-host=,,, +# (you can use 'infinite' for leasetime, or specify in hours like 12h) +# diff --git a/dhcp.conf b/dhcp.conf new file mode 100644 index 0000000..6e95758 --- /dev/null +++ b/dhcp.conf @@ -0,0 +1,18 @@ +# file: dhcp.conf +# description: This file is for user configuration of the dhcp service on dnsmasq. + +### ### +### DHCP Configuration ### +### ### + +# Set up scopes +# dhcp-range=,,,, +#dhcp-range=home_lan,192.168.1.100,192.168.1.200,255.255.255.0,12h + +# Set Gateway Servers (the 3 tag means 'router') +#dhcp-option=home_lan,3,192.168.1.1 + +# Set DNS servers (the 6 tag means 'dns-server') +# dhcp-option=,6, +# range_name is defined above when you defined your ranges. +#dhcp-option=home_lan,6,10.0.0.10 diff --git a/dns.conf b/dns.conf new file mode 100644 index 0000000..9fa39cd --- /dev/null +++ b/dns.conf @@ -0,0 +1,50 @@ +# file: dns.conf +# description: This file is for user configuration of the dns service on dnsmasq. + +### ### +### DNS Configuration ### +### ### + +# Turn off reading of the local /etc/resolv.conf file +# We're setting our upstream servers below, so reading resolv.conf is +# unncecessary +no-resolv + +# Read hosts from here in addition to /etc/hosts +#addn-hosts=/etc/hosts.mydomain +addn-hosts=/etc/dnsmasq.d/hosts.local + +# Add your upstream DNS servers here. You can set as many as you'd like. +# If you don't want to use Quad9 as your upstream provider, replace +# these with servers of your own choosing. +server=9.9.9.9 +server=142.112.112.112 + +# Never forward plain names (without a dot or domain part) +domain-needed + +# Never forward addresses in the non-routed address spaces. +bogus-priv + +# Add local-only domains here, queries in these domains are answered +# from /etc/hosts or DHCP only. +#local=/localnet/ +#local=/internal.example.com/ + +# Set your internal domain +#domain=internal.example.com + +# Expand hosts using 'domain' set above. +expand-hosts + +# Set logging facility +# If there is at least one / in the log-facility, it will be treated +# as a file. dnsmasq will close and reopen the file when it receives +# signal USR2, which allows for log rotation without stopping dnsmasq. +# You'll want to set a bind mount to access this file on your local host +# and manage it's logs using logrotate. +log-facility=/var/log/dnsmasq/dnsmasq.log + +# Turn on query logging. Be warned, this can eat up disk space +# quickly. +#log-queries diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..725b5de --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +dnsmasq -k & + +FILE="/etc/dnsmasq.d/hosts.local" +LAST=`md5sum "$FILE"` +while true; do + sleep 0.1 + NEW=`md5sum "$FILE"` + if [ "$NEW" != "$LAST" ]; then + killall -s SIGHUP dnsmasq + LAST="$NEW" + fi +done diff --git a/hosts.local b/hosts.local new file mode 100644 index 0000000..3c09154 --- /dev/null +++ b/hosts.local @@ -0,0 +1,6 @@ +# file: hosts.local +# description: This file is for setting static DNS entries in dnsmasq. Each line should begin with an IP address, followed by a FQDN. +# Additional terms will be treated as CNAME records (i.e., pointers back to the FQDN). +# + +# 192.168.1.100 example-host1.internal.example.com example-host1 example-web1