Initial commit for creating core dns image

This commit is contained in:
2023-01-26 06:27:17 +00:00
parent 7db856db57
commit 061591808d
6 changed files with 116 additions and 0 deletions

17
Dockerfile Normal file
View File

@@ -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"]

11
dhcp-reservations.conf Normal file
View File

@@ -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=<mac_address>,<ip_address>,<hostname>,<leasetime>
# (you can use 'infinite' for leasetime, or specify in hours like 12h)
#

18
dhcp.conf Normal file
View File

@@ -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=<range_name>,<start_address>,<end_address>,<subnet_mask>,<lease_time>
#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=<range_name>,6,<dns_server_address>
# range_name is defined above when you defined your ranges.
#dhcp-option=home_lan,6,10.0.0.10

50
dns.conf Normal file
View File

@@ -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

14
entrypoint.sh Executable file
View File

@@ -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

6
hosts.local Normal file
View File

@@ -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