├── Dockerfile ├── no-ip.sh └── readme.md /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | RUN apk update && apk add bash wget 3 | COPY no-ip.sh /no-ip.sh 4 | CMD /bin/bash /no-ip.sh -------------------------------------------------------------------------------- /no-ip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | while : 4 | do 5 | 6 | if [ -z "$USER" ] 7 | then 8 | echo "No user was set. Use -u=username" 9 | exit 10 10 | fi 11 | 12 | if [ -z "$PASSWORD" ] 13 | then 14 | echo "No password was set. Use -p=password" 15 | exit 20 16 | fi 17 | 18 | 19 | if [ -z "$HOSTNAME" ] 20 | then 21 | echo "No host name. Use -h=host.example.com" 22 | exit 30 23 | fi 24 | 25 | 26 | if [ -n "$DETECTIP" ] 27 | then 28 | IP=$(wget -qO- "http://myexternalip.com/raw") 29 | 30 | if [ -n "$UPDATEIPV6" ] 31 | then 32 | IPV6=$(wget -q --output-document - http://checkipv6.dyndns.com/ | grep -o "[0-9a-f\:]\{8,\}") 33 | fi 34 | fi 35 | 36 | 37 | if [ -n "$DETECTIP" ] && [ -z $IP ] 38 | then 39 | RESULT="Could not detect external IP." 40 | fi 41 | 42 | 43 | if [[ $INTERVAL != [0-9]* ]] 44 | then 45 | echo "Interval is not an integer." 46 | exit 35 47 | fi 48 | 49 | 50 | SERVICEURL="dynupdate.no-ip.com/nic/update" 51 | 52 | case "$SERVICE" in 53 | noip) 54 | SERVICEURL="dynupdate.no-ip.com/nic/update" 55 | ;; 56 | 57 | dyndns) 58 | SERVICEURL="members.dyndns.org/v3/update" 59 | ;; 60 | 61 | duckdns) 62 | SERVICEURL="www.duckdns.org/v3/update" 63 | ;; 64 | 65 | google) 66 | SERVICEURL="domains.google.com/nic/update" 67 | ;; 68 | 69 | freedns) 70 | SERVICEURL="freedns.afraid.org/nic/update" 71 | ;; 72 | 73 | 74 | *) 75 | SERVICEURL="dynupdate.no-ip.com/nic/update" 76 | 77 | esac 78 | 79 | USERAGENT="--user-agent=\"no-ip shell script/1.0 mail@mail.com\"" 80 | BASE64AUTH=$(echo '"$USER:$PASSWORD"' | base64) 81 | AUTHHEADER="--header=\"Authorization: $BASE64AUTH\"" 82 | 83 | NOIPURL="https://$USER:$PASSWORD@$SERVICEURL" 84 | 85 | 86 | if [ -n "$IP" ] || [ -n "$HOSTNAME" ] 87 | then 88 | NOIPURL="$NOIPURL?" 89 | fi 90 | 91 | if [ -n "$HOSTNAME" ] 92 | then 93 | NOIPURL="${NOIPURL}hostname=${HOSTNAME}" 94 | fi 95 | 96 | if [ -n "$IP" ] 97 | then 98 | if [ -n "$HOSTNAME" ] 99 | then 100 | NOIPURL="$NOIPURL&" 101 | fi 102 | NOIPURL="${NOIPURL}myip=$IP" 103 | if [ -n "$UPDATEIPV6" ] 104 | then 105 | NOIPURL="${NOIPURL},$IPV6&myipv6=$IPV6" 106 | fi 107 | fi 108 | 109 | 110 | echo "$AUTHHEADER $USERAGENT $NOIPURL" 111 | 112 | RESULT=$(wget --no-check-certificate -qO- $AUTHHEADER $USERAGENT $NOIPURL) 113 | 114 | 115 | echo $RESULT 116 | 117 | 118 | if [ $INTERVAL -eq 0 ] 119 | then 120 | break 121 | else 122 | sleep "${INTERVAL}m" 123 | fi 124 | 125 | done 126 | 127 | exit 0 128 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | Docker Dynamic DNS Client 2 | ===== 3 | 4 | Docker Hub: https://hub.docker.com/r/blaize/docker-dynamic-dns/ 5 | 6 | GitHub: https://github.com/theonemule/docker-dynamic-dns 7 | 8 | Author's Site: https://www.blaize.net 9 | 10 | Dynamic DNS services have been around since the early days of the internet. Generally speaking, internet service providers (ISP's) will reassign an IP address to a subscriber after some period of time or if the user reconnects his or her connection. Traditional DNS services, however, relied on IP addresses staying the same. DynDNS developed an HTTP-based protocol for updating DNS records on Dynamic DNS services that has been copied for a number of platforms. One of the real advantages of Dynamic DNS nowadays is that HTTPS can now be bound to a domain name instead of an IP. Likewise, a domain name (ie. subdomain.example.com) can be bound to a dynamic DNS name in a DNS record via a CNAME. So even if one is using a Dynamic DNS, traffic can still be secured using HTTPS. 11 | 12 | Having gotten in to Docker in recent years, I wanted to migrate my existing NO-IP script to a Docker. I modified the script to accept environmental variables as input instead of passing them on the command line and also added two services for DynDNS and DuckDNS in addition to NO-IP. 13 | 14 | To build the Docker image, simply run Docker build 15 | 16 | ``` 17 | docker build --no-cache --tag docker-dynamic-dns . 18 | ``` 19 | 20 | Or you can pull it: 21 | 22 | ``` 23 | docker pull blaize/docker-dynamic-dns 24 | ``` 25 | 26 | To use the image, use Docker run. 27 | 28 | ``` 29 | docker run -it --rm --name no-ip1 -e USER=username -e PASSWORD=yourpassword -e SERVICE=duckdns -e HOSTNAME=example.com -e DETECTIP=1 -e INTERVAL=1 blaize/docker-dynamic-dns 30 | ``` 31 | 32 | The envitonmental variables are as follows: 33 | 34 | * **USER**: the username for the service. 35 | 36 | * **PASSWORD**: the password or token for the service. 37 | 38 | * **HOSTNAME**: The host name that you are updating. ie. example.com 39 | 40 | * **DETECTIP**: If this is set to 1, then the script will detect the external IP of the service on which the container is running, such as the external IP of your DSL or cable modem. 41 | 42 | * **IP**: if DETECTIP is not set, you can specify an IP address. 43 | 44 | * **UPDATEIPV6**: If this is set to 1, then the script will detect the external IPv6 address of the service on which the container is running. 45 | 46 | * **INTERVAL**: How often the script should call the update services in minutes. 47 | 48 | * **SERVICE**: The service you are using. Currently, the script is setup to use Google Domains (google), DuckDNS (duckdns), DynDNS (dyndns), and NO-IP (noip). Set the service to the value in parenthesis. 49 | 50 | That's it. Please comment below if there are other services using the DynDNS protocol you would like me to add. 51 | --------------------------------------------------------------------------------