autonomous dns

This commit is contained in:
f 2021-04-01 15:49:14 -03:00
parent 45c8f985c7
commit 72e5499ab9
4 changed files with 40 additions and 10 deletions

View file

@ -1,4 +1,4 @@
FROM alpine:3.13.2 AS build FROM alpine:3.13.3 AS build
ENV EMAIL monit@sutty.nl ENV EMAIL monit@sutty.nl
RUN apk add --no-cache tzdata RUN apk add --no-cache tzdata
@ -7,33 +7,33 @@ COPY ./monitrc /etc/monitrc
RUN chmod 600 /etc/monitrc RUN chmod 600 /etc/monitrc
RUN sed -re "s/@@EMAIL@@/${EMAIL}/" -i /etc/monitrc RUN sed -re "s/@@EMAIL@@/${EMAIL}/" -i /etc/monitrc
FROM alpine:3.13.2 FROM alpine:3.13.3
MAINTAINER "f <f@sutty.nl>" MAINTAINER "f <f@sutty.nl>"
# TODO: We don't want to receive lots of email, so we'll change this to # TODO: We don't want to receive lots of email, so we'll change this to
# a pingy instance that will also work as a status site. # a pingy instance that will also work as a status site.
ENV EMAIL monit@sutty.nl ENV EMAIL monit@sutty.nl
# Sutty's repository
RUN echo https://alpine.sutty.nl/alpine/v3.13/sutty >> /etc/apk/repositories
RUN wget https://alpine.sutty.nl/alpine/sutty.pub -O /etc/apk/keys/alpine@sutty.nl-5ea884cd.rsa.pub
# Install monit and remove default config # Install monit and remove default config
RUN apk upgrade --no-cache RUN apk add --no-cache tini monit knsupdate
RUN apk add --no-cache tini monit
COPY --from=build /usr/share/zoneinfo/UTC /etc/localtime COPY --from=build /usr/share/zoneinfo/UTC /etc/localtime
# Create directories # Create directories
RUN install -dm 2750 -o root -g root /etc/monit.d RUN install -dm 2750 -o root -g root /etc/monit.d
RUN install -dm 2750 -o root -g root /var/lib/monit RUN install -dm 2750 -o root -g root /var/lib/monit
# Install config. monit.conf~ will be activated after allow_networks # Install config
# runs.
COPY --from=build /etc/monitrc /etc/monitrc COPY --from=build /etc/monitrc /etc/monitrc
COPY ./nsupdate.sh /usr/local/bin/nsupdate
COPY ./whatsmyip6.sh /usr/local/bin/whatsmyip6
# Allow access to the web GUI # Allow access to the web GUI
EXPOSE 2812 EXPOSE 2812
# Sutty's repository
RUN echo 'https://alpine.sutty.nl/alpine/v3.13/sutty' >> /etc/apk/repositories
RUN wget https://alpine.sutty.nl/alpine/sutty.pub -O /etc/apk/keys/alpine@sutty.nl-5ea884cd.rsa.pub
# Use tini as init # Use tini as init
ENTRYPOINT ["/sbin/tini", "--"] ENTRYPOINT ["/sbin/tini", "--"]

View file

@ -13,4 +13,9 @@ set httpd port 2812
allow localhost allow localhost
allow 172.0.0.0/8 allow 172.0.0.0/8
check program nsupdate
with path "/usr/local/bin/nsupdate"
every 1 cycle
if status = 0 then unmonitor
include /etc/monit.d/*.conf include /etc/monit.d/*.conf

22
nsupdate.sh Executable file
View file

@ -0,0 +1,22 @@
#!/bin/sh
# Registers the local IPv6 address to the DNS
IP6="`whatsmyip6`"
KNOT="${KNOT:-${IP6}}"
test -z "${IP6}" && exit 1
test -z "${KNOT}" && exit 1
test -z "${DOMAIN}" && exit 1
knsupdate <<DNS
server ${KNOT}
zone ${DOMAIN}.
origin ${DOMAIN}.
ttl 60
add ${HOSTNAME} AAAA ${IP6}
send
quit
DNS
exit $?

3
whatsmyip6.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
ip address show ${1:-eth0} | grep inet6 | grep global | tr -s " " | cut -d " " -f 3 | cut -d / -f 1