This script allows you to automatically update DNS records for your domain/subdomains on Porkbun using their API. It ensures your records are always in sync with your current public IP.
bash <(curl -Ls "https://raw.githubusercontent.com/StafLoker/ddns-porkbun-script/main/install.sh")
To install your desired version, use following installation command. e.g., version v1.0.1
:
VERSION=v1.0.1 && bash <(curl -Ls "https://raw.githubusercontent.com/StafLoker/ddns-porkbun-script/main/install.sh") $VERSION
-
Install
jq
:
jq
is a lightweight and flexible command-line JSON processor, required to parse API responses.sudo apt install jq
-
Create
keys.env
file:
Store your API keys securely in an environment file. Replacepk
andsk
with your actual API and Secret API keys from Porkbun.echo 'PORKBUN_API_KEY="pk"' > keys.env echo 'PORKBUN_SECRET_API_KEY="sk"' >> keys.env
Make sure to secure this file:
chmod 600 keys.env
-
Configure your domain and subdomains:
Create thedata.json
file to include your domain and subdomains. Example format:{ "domain": "example.com", "concurrency": true, "ipv4": true, "subdomains_type_a": [ "sub1", "sub2" ], "ipv6": false, "subdomains_type_aaaa": [ "sub3", "sub4" ] }
-
Make the script executable:
Ensure the script has executable permissions:chmod +x ddns-porkbun-script.sh
To automate the script, use cron
to schedule periodic and system startup executions:
-
Open crontab for editing:
crontab -e
-
Add the following entries:
- Run every hour: Updates DNS records every hour.
- Run on system reboot: Ensures DNS updates upon system startup.
# Every 1 hour 0 * * * * /path/to/ddns-porkbun-script.sh # At system reboot @reboot /path/to/ddns-porkbun-script.sh
-
Save and exit the crontab editor.
-
Updating
ddns-porkbun-script.sh
for Cron Compatibility Here is the updated snippet of theddns-porkbun-script.sh
file:# Load keys source /absolute/path/to/keys.env # Load JSON DATA_FILE="/absolute/path/to/data.json"
Verifying:
- Edit your Cron job to point to the updated
ddns-porkbun-script.sh
file. - Execute the script manually to confirm it works without errors:
/absolute/path/to/ddns-porkbun-script.sh
- Edit your Cron job to point to the updated
- Environment File: Ensure the
keys.env
file is not accessible to other users on the system. Usechmod 600
to restrict permissions. - Avoid Hardcoding Keys: Use the
source
command to load environment variables securely.
To test the script manually, run:
./ddns-porkbun-script.sh
Verify that the DNS records on Porkbun are updated to match your current public IP.
Check logs
journalctl -t ddns-porkbun | tail
This project is released under the MIT License. See the LICENSE file for more details.