ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Dynamic DNS with CloudFlare

    IT Discussion
    cloudflare api linux dns edge router
    8
    25
    4.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NashBrydgesN
      NashBrydges
      last edited by NashBrydges

      Interesting feature with Cloudflare that I just discovered is that they flatten a CNAME record to the root of the domain. So I can enter my DDNS domain as a CNAME record. It will query the IP of that domain and return the IP address to use for the root domain. So this script isn't really needed since it will do the lookup for you.

      B stacksofplatesS 2 Replies Last reply Reply Quote 0
      • NashBrydgesN
        NashBrydges
        last edited by

        0_1519848967546_03ce84de-9460-4f81-ae28-0d14371addf8-image.png

        1 Reply Last reply Reply Quote 0
        • B
          bnrstnr @NashBrydges
          last edited by bnrstnr

          @nashbrydges said in Dynamic DNS with CloudFlare:

          Where do you obtain your record ID?

          #!/bin/bash
          
          key="Your_Global_API_Key"
          zoneID="Your_Zone_ID"
          email="[email protected]"
          recordName="example.com"
          
          curl -X GET "https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records?type=A&name=$recordName" \
               -H "X-Auth-Email: $email" \
               -H "X-Auth-Key: $key" \
               -H "Content-Type: application/json"
          
          1 Reply Last reply Reply Quote 0
          • B
            bnrstnr @NashBrydges
            last edited by bnrstnr

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • B
              bnrstnr
              last edited by

              @NashBrydges I would have bet money that the $recordID was just the short name of the record (ie. "sub" of "sub.example.com"). I swear I did it like that and it worked, but apparently not :flushed_face:.

              The script to get the real identifier is above.

              NashBrydgesN 1 Reply Last reply Reply Quote 0
              • NashBrydgesN
                NashBrydges @bnrstnr
                last edited by

                @bnrstnr said in Dynamic DNS with CloudFlare:

                @NashBrydges I would have bet money that the $recordID was just the short name of the record (ie. "sub" of "sub.example.com"). I swear I did it like that and it worked, but apparently not :flushed_face:.

                The script to get the real identifier is above.

                Thanks. I'll give that a try later.

                1 Reply Last reply Reply Quote 0
                • stacksofplatesS
                  stacksofplates @NashBrydges
                  last edited by

                  @nashbrydges said in Dynamic DNS with CloudFlare:

                  Interesting feature with Cloudflare that I just discovered is that they flatten a CNAME record to the root of the domain. So I can enter my DDNS domain as a CNAME record. It will query the IP of that domain and return the IP address to use for the root domain. So this script isn't really needed since it will do the lookup for you.

                  Ya I don’t have a DDNS name so that’s why I Serb it up this way.

                  1 Reply Last reply Reply Quote 0
                  • 3
                    360col
                    last edited by

                    Very useful. bookmarking this!

                    1 Reply Last reply Reply Quote 0
                    • NashBrydgesN
                      NashBrydges
                      last edited by

                      I've confirmed that Cloudflare's CNAME flattening feature works exactly as advertised.

                      Create a CNAME record with following values:

                      • Type = CNAME
                      • Name = Your root mydomain.com domain name
                      • Domain Name = Your DDNS domain subdomain.ddns.net (I use No-IP for example but change yours as needed)

                      I then created another CNAME record to handle the www subdomain and everything works as expected. Both root domain name and www route correctly.

                      B 1 Reply Last reply Reply Quote 0
                      • B
                        bnrstnr @NashBrydges
                        last edited by

                        @nashbrydges I thought somebody already said this, but I cant find it. The only bad part about the CNAME method if you're using a free account on no-ip, then you have to login to their site and confirm that you're still using the DDNS every 30 days, which is a PITA. Setup the script with a cron job and never have to worry about checking in on no-ip or afraid.org every n days.

                        NashBrydgesN JaredBuschJ 2 Replies Last reply Reply Quote 0
                        • B
                          bnrstnr
                          last edited by bnrstnr

                          @stacksofplates said in Dynamic DNS with CloudFlare:

                          ip=$(curl http://icanhazip.com)

                          While I was looking into the Cloudflare API a little further yesterday, I came across this. I don't know much about it, but here it is.

                          Consider replacing curl -s http://icanhazip.com with dig +short myip.opendns.com @resolver1.opendns.com. It works exactly the same.

                          Querying icanhazip.com or other similar sites requires a fairly expensive TCP connection, HTTP overhead, etc. This can be burdensome when queried regularly via cron jobs. A UDP-based DNS connection is considerably faster, lighter weight, and uses far less resources.

                          1 Reply Last reply Reply Quote 0
                          • NashBrydgesN
                            NashBrydges @bnrstnr
                            last edited by

                            @bnrstnr said in Dynamic DNS with CloudFlare:

                            @nashbrydges I thought somebody already said this, but I cant find it. The only bad part about the CNAME method if you're using a free account on no-ip, then you have to login to their site and confirm that you're still using the DDNS every 30 days, which is a PITA. Setup the script with a cron job and never have to worry about checking in on no-ip or afraid.org every n days.

                            That's correct, if you have the free account with No-IP you have to reconfirm every 30 days. I have the paid account so that's not a problem. It doesn't expire.

                            stacksofplatesS 1 Reply Last reply Reply Quote 1
                            • JaredBuschJ
                              JaredBusch @bnrstnr
                              last edited by

                              @bnrstnr said in Dynamic DNS with CloudFlare:

                              @nashbrydges I thought somebody already said this, but I cant find it. The only bad part about the CNAME method if you're using a free account on no-ip, then you have to login to their site and confirm that you're still using the DDNS every 30 days, which is a PITA. Setup the script with a cron job and never have to worry about checking in on no-ip or afraid.org every n days.

                              afraid.org does require reauth but like every 6 months or so.

                              1 Reply Last reply Reply Quote 1
                              • B
                                bnrstnr
                                last edited by

                                To each their own... I'll opt for the free, never reauth, option for 3 minutes of setup.

                                1 Reply Last reply Reply Quote 0
                                • stacksofplatesS
                                  stacksofplates @NashBrydges
                                  last edited by

                                  @nashbrydges said in Dynamic DNS with CloudFlare:

                                  @bnrstnr said in Dynamic DNS with CloudFlare:

                                  @nashbrydges I thought somebody already said this, but I cant find it. The only bad part about the CNAME method if you're using a free account on no-ip, then you have to login to their site and confirm that you're still using the DDNS every 30 days, which is a PITA. Setup the script with a cron job and never have to worry about checking in on no-ip or afraid.org every n days.

                                  That's correct, if you have the free account with No-IP you have to reconfirm every 30 days. I have the paid account so that's not a problem. It doesn't expire.

                                  Ya this is why I set this up. I’m cheap and I was tired of reauth with no-ip.

                                  1 Reply Last reply Reply Quote 0
                                  • RomoR
                                    Romo
                                    last edited by

                                    Edgerouters can now handle custom dynamic dns providers without the need of the script - here is the guide with Cloudflare as the example: https://help.ubnt.com/hc/en-us/articles/204976324

                                    1 Reply Last reply Reply Quote 4
                                    • 1
                                    • 2
                                    • 2 / 2
                                    • First post
                                      Last post