Bind9 DDNS in Docker

vi dockerfile_ddns
FROM ubuntu:latest
RUN apt-get update && apt-get install bind9 vim curl dnsutils cron -y && apt-get clean -y && rm -r /var/lib/apt/lists/*
RUN touch /root/do-nsupdate && chmod 755 /root/do-nsupdate && echo '*/5 * * * * root /root/do-nsupdate' >> /etc/crontab
CMD service cron start && tail -f /var/log/lastlog

docker build -f dockerfile_ddns -t ddns --no-cache=true .

vi dockercompose_ddns.yml
services:
  service:
    image: ddns:latest
    volumes:
      - volume:/root
    restart: unless-stopped
    container_name: DDNS_TKO
    network_mode: bridge
# command:
# - sleep
# - infinity
volumes:
  volume:
    driver: local

docker compose -p ddns -f dockercompose_ddns.yml up -d

docker exec -it DDNS_Home bash

vi /root/do-nsupdate
#!/bin/bash

updateServer=ns1.mybind9nameserver.com
updateDomain=mydomain.com
encryptKeyPath="/root/mydomain.com.key"
checkIPWeb="http://checkip.amazonaws.com/"

CURRENT_IP=$(nslookup $updateDomain $updateServer| grep Address | grep -v "#53")
CURRENT_IP=$(echo ${CURRENT_IP:9})

EXT_IP=$(curl $checkIPWeb)

if [ $CURRENT_IP != $EXT_IP ]; then
KEY=$encryptKeyPath

cat <<EOF | nsupdate -k “$KEY"
server $updateServer
update delete $updateDomain. A
update add $updateDomain. 3600 A $EXT_IP
send
EOF
fi

Comments

No comments yet. Why don’t you start the discussion?

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

*