first commit

This commit is contained in:
Mabe
2026-05-07 20:53:10 +02:00
commit 7ddff5ac9b
16 changed files with 1359 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
> [!IMPORTANT]
> It is only for Hetzners RRSets in the cloud console
# Hetzner DynDNS (A-Records) based on a bash script.
The script uses the cloud API to update a RRSet. You can use different flags for different records (subdomains)
This script uses the zoneID not the zone name.
It´s easy to use and setting up the script should function by following the Readme.
Requirements: `curl`, `git`
## Installation
```ini
git clone https://github.com/mabe1489/Hetzner-DynDNS-RRSet.git
cd Hetzner-DynDNS-RRSet/
```
## Configuration
### Script Configuration
> [!IMPORTANT]
> You need your ZoneID and your API-Token
You need an API Token: Your project > security > API-Tokens > Create one with read and write access.
You need your zoneID: run the zoneID script: `bash ./zoneID.sh -t YOUR_API-TOKEN`.
Now save your zoneID in the ddns.sh in ZONE_ID and also enter your API-Token in API-TOKEN.
> [!IMPORTANT]
> You have to use the zoneID wich is the highest result of the `zoneID.sh`
With the flag `-n` you can enter your record name.
### Preconfiguration
After that installing a cronjob with:
```crontab
crontab -e
*/10 * * * * bash YourFolder/ddns.sh -n Your-Record-Name
```
## Thank you
Have fun and send issues in the issue tab (That would be really nice)
+64
View File
@@ -0,0 +1,64 @@
#!/bin/bash
set -euo pipefail
# ddns.sh
# Updates a Hetzner Cloud zone rrset A record to the current public IPv4.
#
# Usage: ./ddns.sh [-t API_TOKEN] [-z ZONE_ID] [-n RRSET_NAME]
# -t: Hetzner API token
# -z: Zone ID
# -n: RRSET name
# Default values
API_TOKEN="Your-API-Token"
ZONE_ID="zone_ID-For_Information_look_at_the_readme"
RRSET_NAME="Record-name"
# Parse command line arguments
while getopts ":t:z:n:" opt; do
case $opt in
t) API_TOKEN="$OPTARG";;
z) ZONE_ID="$OPTARG";;
n) RRSET_NAME="$OPTARG";;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# Validate required parameters
if [ "$API_TOKEN" = "Ihr-API-Token-hier" ]; then
echo "Error: API Token is required. Use -t option or set it in the script." >&2
exit 1
fi
# Get current public IPv4 (trim newline)
CURRENT_IPV4=$(curl -fsS https://ipv4.icanhazip.com | tr -d '\n')
if [ -z "$CURRENT_IPV4" ]; then
echo "Failed to determine public IPv4. Exiting." >&2
exit 1
fi
JSON_PAYLOAD=$(cat <<EOF
{"records":[{"value":"$CURRENT_IPV4","comment":""}]}
EOF
)
API_URL="https://api.hetzner.cloud/v1/zones/${ZONE_ID}/rrsets/${RRSET_NAME}/A/actions/set_records"
echo "Updating A record '$RRSET_NAME' in zone id $ZONE_ID to $CURRENT_IPV4"
curl -fsS -X POST \
-H "Authorization: Bearer $API_TOKEN" \
-H "Content-Type: application/json" \
-d "$JSON_PAYLOAD" \
"$API_URL" \
|| { echo "API request failed" >&2; exit 2; }
echo "Update request sent."
+24
View File
@@ -0,0 +1,24 @@
#!/bin/bash
# -t: Hetzner API token
API_TOKEN="Your-API-Token"
while getopts ":t:z:n:" opt; do
case $opt in
t) API_TOKEN="$OPTARG";;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
curl \
-H "Authorization: Bearer $API_TOKEN" \
"https://api.hetzner.cloud/v1/zones/"