DDNS on Porkbun

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Author Message
ohmic314
DD-WRT Novice


Joined: 09 Dec 2011
Posts: 8

PostPosted: Sun Oct 27, 2024 4:51    Post subject: DDNS on Porkbun Reply with quote
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.
    - Use this website from Porkbun to get the API key and Secret key for your account: https://kb.porkbun.com/article/190-getting-started-with-the-porkbun-api
    - Ssh into the router and run the following command - replace the $DOMAIN, $SECRET_KEY, and $APIKEY with your domain, secret key, and apikey that was obtained from the previous step
    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!
Sponsor
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum