ohmic314 DD-WRT Novice
Joined: 09 Dec 2011 Posts: 8
|
Posted: Sun Oct 27, 2024 4:51 Post subject: DDNS on Porkbun |
|
I was unable to get DDNS working with Porkbun using the dd-wrt web GUI, so I thought I would just write a little how-to in case someone else needs help setting it up.
Code: | curl -sb -X POST https://api.porkbun.com/api/json/v3/dns/retrieve/$DOMAIN -H "Content-Type: application/json" -d "{\"secretapikey\":\"$SECRET_KEY\",\"apikey\":\"$APIKEY\"}" |
- Record the ID for the domain/subdomain that you're looking to update with dd-wrt
For example, the code will return something like:
{"status":"SUCCESS","cloudflare":"enabled","records":[{"id":"31415926","name":"subdomain.domain.com","type":"A","content":"5.5.5.5","ttl":"600","prio":"0","notes":null}...
The id that you need is: 31415926
- Go to dd-wrt menu item Administration -> Commands box and copy/paste the following code. Be sure to replace YOUR_DOMAIN, YOUR_SECRET_KEY, YOUR_APIKEY, and ID with the ones for your domain
Code: | #!/bin/sh
# Get the current WAN ip address
CURRENT_IP=`nvram get wan_ipaddr`
# These options are to retrieve IP address in case of double NAT
#CURRENT_IP=$(curl -fs4 https://myip.dnsomatic.com/)
#CURRENT_IP=$(curl -fs4 http://checkip.amazonaws.com/)
#CURRENT_IP=$(curl --silent http://api.ipify.org/)
# Compare with the last saved address
if grep -q "$CURRENT_IP" /tmp/last_wan_ip;
then
echo DDNS: No change needed
else
echo DDNS: Change needed
# Write the current IP to the file to compare to later
echo $CURRENT_IP > /tmp/last_wan_ip
APIKEY="YOUR_APIKEY"
SECRET_KEY="YOUR_SECRET_KEY"
DOMAIN="YOUR_DOMAIN"
SUBDOMAIN="YOUR_SUBDOMAIN"
ID="YOUR_ID"
RESPONSE=$(curl -sb \
-X POST https://api.porkbun.com/api/json/v3/dns/edit/$DOMAIN/$ID \
-H "Content-Type: application/json" \
-d "{\"secretapikey\":\"$SECRET_KEY\",\"apikey\":\"$APIKEY\",\"name\":\"$SUBDOMAIN\",\"type\":\"A\",\"content\":\"$CURRENT_IP\"}")
fi |
- Click Save Custom
- Go to Administration -> Management -> Cron -> Additional Jobs and add instructions to run the .rc_custom script every minute and force update every day at 2am
Code: | * * * * * root /tmp/.rc_custom
30 2 * * * root rm /tmp/last_wan_ip |
- Save and Apply/reboot
I hope this helps someone out there! |
|