1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

Custom DDNS failing

Discussion in 'Asuswrt-Merlin' started by D34DC3N73R, Mar 17, 2018.

Tags:
  1. D34DC3N73R

    D34DC3N73R New Around Here

    Joined:
    Dec 17, 2017
    Messages:
    9
    I've used the DDNS sample script for cloudflare, but it doesn't seem to be working and I'm not seeing enough detail to figure out why it's not working. I have an RT-AC88U on 380.69

    /jffs/scripts/ddns-start
    Code:
    #!/bin/sh
    
    EMAIL="[email protected]ld"
    ZONEID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    RECORDID="xxxxxxxxxx"
    RECORDNAME="domain.tld"
    API="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    IP=${1}
    
    curl -fs -o /dev/null -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONEID/dns_records/$RECORDID" \
      -H "X-Auth-Email: $EMAIL" \
      -H "X-Auth-Key: $API" \
      -H "Content-Type: application/json" \
      --data "{\"type\":\"A\",\"name\":\"$RECORDNAME\",\"content\":\"$IP\",\"ttl\":120,\"proxied\":false}"
    
    if [ $? -eq 0 ]; then
      /sbin/ddns_custom_updated 1
    else
      /sbin/ddns_custom_updated 0
    fi
    
    When running the script or saving the DDNS section, I get a warning prompt "Request error! Please try again."

    The system log shows:

    Mar 17 18:56:31 rc_service: watchdog 617:notify_rc start_ddns
    Mar 17 18:56:31 custom_script: Running /jffs/scripts/ddns-start (args: xxx.xxx.xxx.xxx)
    Mar 17 18:56:33 ddns: Custom ddns update failed
     
    Last edited: Mar 17, 2018
  2. Please support SNBForums! Just click on this link before you buy something from Amazon and we'll get a small commission on anything you buy. Thanks!
  3. Zirescu

    Zirescu Very Senior Member

    Joined:
    Jul 16, 2013
    Messages:
    721
    Location:
    Kelowna, BC
    If you try running the curl command with the values entered from the command line does it succeed?
     
  4. D34DC3N73R

    D34DC3N73R New Around Here

    Joined:
    Dec 17, 2017
    Messages:
    9
    The command appears to run successfully. However, when I enter a different ip address than my current ip, and log into CF no change has been made. All the A records still point to my current/original ip.
     
  5. Zirescu

    Zirescu Very Senior Member

    Joined:
    Jul 16, 2013
    Messages:
    721
    Location:
    Kelowna, BC
  6. D34DC3N73R

    D34DC3N73R New Around Here

    Joined:
    Dec 17, 2017
    Messages:
    9
    Appreciate the effort. I'm also new to cloudflare, but it seems straightforward enough (with the exception of debugging this api call). I've whitelisted all of CFs ip ranges and still haven't come up with anything.
     
  7. D34DC3N73R

    D34DC3N73R New Around Here

    Joined:
    Dec 17, 2017
    Messages:
    9
    modified the curl command to output the response from cloudflare.
    Code:
    {
      "success": false,
      "errors": [
        {
          "code": 7003,
          "message": "Could not route to \/zones\/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\/dns_records\/xxxxxxxxxx, perhaps your object identifier is invalid?"
        },
        {
          "code": 7000,
          "message": "No route for that URI"
        }
      ],
      "messages": [
      
      ],
      "result": null
    }
    
    I double checked the zone and reran the following to check my record id was correct (it was)
    Code:
    curl https://www.cloudflare.com/api_json.html \
      -d a=rec_load_all \
      -d tkn=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
      -d [email protected] \
      -d z=domain.tld
    
    Not really sure what the problem is since I just double checked the zone and record id. I wouldn't be able to attain the record id if my email or api key were incorrect. Certainly would appreciate any other ideas or advice.
     
  8. D34DC3N73R

    D34DC3N73R New Around Here

    Joined:
    Dec 17, 2017
    Messages:
    9
    I made some progress and can manually update ip via command line. However, after replacing the curl command in the script and then running the script I get the error "Record content cannot be empty." It did not seem like the ip variable was being set.

    So, I modified the script which relies on a third party site ifconfig.co to get wan ip.

    Code:
    #!/bin/sh
    
    EMAIL="[email protected]"
    RECORDID="xxxxxxxxxx"
    RECORDNAME="domain.tld"
    API="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    IP="$(curl -s v4.ifconfig.co)"
    
    curl -fs -o /dev/null https://www.cloudflare.com/api_json.html \
      -d a=rec_edit \
      -d tkn=$API \
      -d id=$RECORDID \
      -d email=$EMAIL \
      -d z=$RECORDNAME \
      -d type=A \
      -d name=$RECORDNAME \
      -d ttl=120 \
      -d content=$IP
    
    if [ $? -eq 0 ]; then
      /sbin/ddns_custom_updated 1
    else
      /sbin/ddns_custom_updated 0
    fi
    
    I would like to find out why IP doesn't return anything on the default script so I don't have to rely on ifconfig.co. I'm not sure why the original script wasn't working for me in the first place. Also, I basically have no idea what I'm doing so I'm not sure what the benefits/drawbacks are to this approach over the default script.
     
  9. D34DC3N73R

    D34DC3N73R New Around Here

    Joined:
    Dec 17, 2017
    Messages:
    9
    Anyone else out there using custom DDNS? Any ideas why ${1} isn't returning the wan ip? Any insight as to where that code is located would be appreciated too. FWIW, the correct WAN ip is displayed upon logging in.
     
  10. IsaacFL

    IsaacFL Regular Contributor

    Joined:
    Oct 31, 2016
    Messages:
    61
    I have used custom DDNS before, but currently not using it with 384.4, but it should be the same.

    This is a script that I used for DuckDNS, with ipv6, and ${1} definitely has the WAN ip.
    I would suggest, using logger, to print the string so you see what is going on.

    Code:
    #!/bin/sh
    
    I4=${1}
    IPRE=$(nvram get ipv6_prefix)
    I6=${IPRE/::/:215:5dff:fe01:be2e}
    
    
    # register a subdomain at https://www.duckdns.org/ to get your token
    SUBDOMAIN="xxxxx"
    TOKEN="yyyyyyyyyyy"
    
    
    if [ -n "$I6" ]; then
            curl --silent "https://www.duckdns.org/update?domains=$SUBDOMAIN&token=$TOKEN&ip=$I4&ipv6=$I6" >/dev/null 2>&1
            if [ $? -eq 0 ]; then
                    logger "DDNS updated: $I4 $I6"
                        /sbin/ddns_custom_updated 1
                else
                    logger "DDNS Error: $I4 $I6"
                        /sbin/ddns_custom_updated 0
                fi
        else
            logger "DDNS: IP Address for $I6 needed"
            /sbin/ddns_custom_updated 0
        fi
    
     
  11. D34DC3N73R

    D34DC3N73R New Around Here

    Joined:
    Dec 17, 2017
    Messages:
    9
    Thanks! I was able to get the wan ip using `nvram get wan0_ipaddr`. I've since upgraded to 384.4_2 but still couldn't get the ${1} variable to work. However, I'm pretty happy with this solution so it's probably going to stay this way.
     
  12. Pila

    Pila Regular Contributor

    Joined:
    Jan 21, 2016
    Messages:
    140
    Location:
    Croatia
    If you are talking about the $1 argument passed to the script which contains WAN IP address as known by the router - it is passed to the script only when the router calls it after eg. a boot

    Code:
    Aug  1 02:00:31 custom script: Running /jffs/scripts/ddns-start (args: 192.168.10.10)
    Plus, in the above situation, NTP was not yet done so https will fail at this point, too. OK, in my case, this is a DoubleNAT situation, but is irrelevant here.

    If you run this script manually you would have to call it with the WAN IP adddress which you entered as an argument to the script. Or use external info. Or read it from the router (NVRAM).
     
  13. D34DC3N73R

    D34DC3N73R New Around Here

    Joined:
    Dec 17, 2017
    Messages:
    9
    Thanks for the insight. When trying to get the $1 variable I was also trying regular boots in addition to running the script manually, so I'm not sure what the issue was but I'm happy getting the IP from NVRAM.
     
Please support SNBForums! Just click on this link before you buy something from Amazon and we'll get a small commission on anything you buy. Thanks!