mirror of
https://github.com/JamesTurland/JimsGarage.git
synced 2024-11-21 15:30:19 +00:00
ddns
This commit is contained in:
parent
103c54c378
commit
c3878b28ce
3 changed files with 67 additions and 0 deletions
20
DynamicDNS/config
Normal file
20
DynamicDNS/config
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
## WARNING: set deamon at least to 600 seconds if you use checkip or you could
|
||||||
|
## get banned from their service.
|
||||||
|
daemon=600 # check every 600 seconds (10mins)
|
||||||
|
ssl=yes # use ssl-support
|
||||||
|
use=web # acquire current IP address via web URL
|
||||||
|
|
||||||
|
# Override IP address provider since SSL=yes currently breaks
|
||||||
|
# the default (non-SSL) provider in my version of ddclient.
|
||||||
|
# GitHub issue: https://github.com/ddclient/ddclient/issues/597
|
||||||
|
web=checkip.dyndns.org/
|
||||||
|
web-skip='Current IP Address:' # Probably not needed but doesn't hurt
|
||||||
|
|
||||||
|
##
|
||||||
|
## Cloudflare
|
||||||
|
protocol=cloudflare, \
|
||||||
|
zone=example.com, \
|
||||||
|
ttl=1, \
|
||||||
|
login=email, \
|
||||||
|
password=YOUR_API_TOKEN \
|
||||||
|
example.com,sub1.example.com,sub2.example.com,sub3.example.com
|
12
DynamicDNS/docker-compose.yaml
Normal file
12
DynamicDNS/docker-compose.yaml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
services:
|
||||||
|
ddclient:
|
||||||
|
image: lscr.io/linuxserver/ddclient:latest
|
||||||
|
container_name: ddclient
|
||||||
|
environment:
|
||||||
|
- PUID=1000
|
||||||
|
- PGID=1000
|
||||||
|
- TZ=Etc/UTC
|
||||||
|
volumes:
|
||||||
|
- /home/ubuntu/docker/ddns/config:/config
|
||||||
|
restart: unless-stopped
|
35
DynamicDNS/script.sh
Normal file
35
DynamicDNS/script.sh
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Cloudflare API details
|
||||||
|
ZONE_ID="your_zone_id"
|
||||||
|
RECORD_ID="your_record_id"
|
||||||
|
API_TOKEN="your_cloudflare_api_token"
|
||||||
|
RECORD_NAME="your_domain.com"
|
||||||
|
|
||||||
|
# Get the current external IP
|
||||||
|
CURRENT_IP=$(curl -s http://ipv4.icanhazip.com/)
|
||||||
|
|
||||||
|
# Get the IP stored in Cloudflare
|
||||||
|
CLOUDFLARE_IP=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
|
||||||
|
-H "Authorization: Bearer $API_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" | jq -r '.result.content')
|
||||||
|
|
||||||
|
# Compare the IPs
|
||||||
|
if [ "$CURRENT_IP" != "$CLOUDFLARE_IP" ]; then
|
||||||
|
echo "IP has changed from $CLOUDFLARE_IP to $CURRENT_IP. Updating DNS record..."
|
||||||
|
|
||||||
|
# Update the Cloudflare DNS record
|
||||||
|
UPDATE_RESPONSE=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/$RECORD_ID" \
|
||||||
|
-H "Authorization: Bearer $API_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
--data '{"type":"A","name":"'"$RECORD_NAME"'","content":"'"$CURRENT_IP"'","ttl":120,"proxied":false}')
|
||||||
|
|
||||||
|
# Check if the update was successful
|
||||||
|
if echo "$UPDATE_RESPONSE" | jq -r '.success' | grep -q true; then
|
||||||
|
echo "DNS record updated successfully."
|
||||||
|
else
|
||||||
|
echo "Failed to update DNS record. Response from Cloudflare: $UPDATE_RESPONSE"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "IP has not changed. No update needed."
|
||||||
|
fi
|
Loading…
Reference in a new issue