Sign inSign up

spaskifilip/cloudflare-dns-updater

By spaskifilip

•Updated about 1 year ago

Update Cloudflare DNS Records with the public IP address

Image
Security
API management
Web servers
1

1.5K

spaskifilip/cloudflare-dns-updater repository overview

⁠Cloudflare DNS Updater⁠

DNS Updater is a Python-based tool that automatically updates Cloudflare DNS records with your public IP address. If your server's IP address changes frequently or you have a dynamic IP, this tool ensures that your domains and subdomains always point to the correct server. It can handle multiple domains and subdomains from multiple zones, with proxying enabled or disabled. The tool runs checks and updates every 5 minutes and includes redundancy for IP checking services.

⁠Original idea from Alexandru-Ioan Plesoiu: https://github.com/alexplesoiu/dns-updater⁠

⁠Features

  • Update multiple domains/subdomains from different zones
  • Enable or disable proxying for each domain
  • Redundancy for IP checking services
  • Automatically runs checks and updates every 5 minutes
  • Docker support for easy deployment

⁠Prerequisites

  • Python 3.11
  • Docker (optional)

⁠Installation - Using docker compose file

#Docker compose for cloudflare-dns-updater
version: "3.6"
services:
  cloudlfare-dns-updater:
    image: "spaskifilip/cloudflare-dns-updater:latest"
    container_name: "cloudlfare-dns-updater"
    volumes:
      - app-data:/app # optional unless using the domains.json file and DOMAINS_FILE_PATH variable
    environment:
      CF_API_TOKEN: "YOUR_API_TOKEN" # Recomended to create a token for the zones, not use the main token
	  CF_ZONE_ID: "YOUR_ZONE_ID1,YOUR_ZONE_ID2" # Can be only 1 zone ID (usually is)
	  # Choose the method in which you get your domain records:
	  #   You must choose one method
	  #   DOMAINS_FILE_PATH is not needed if the DOMAINS or DNS_RECORD_COMMENT_KEY variables are set.
	  #   Edit the domains.json according to the example file in the mounted volume.
	  #   If you don't mount a volume, you cannot use the domains.json file and DOMAINS_FILE_PATH variable.
	  DNS_RECORD_COMMENT_KEY: "Comm1,Comm2" # Any DNS reccord that has any of the comments specified here. Can be 1 comment
	  #DOMAINS: "domain.com,example1.domain.com,example2.domain.com"
	  #DOMAINS_FILE_PATH: .\domains.json
	  SCHEDULE_MINUTES: 5
	  PROXIED: True # if proxied is set to True, TTL cannot be set/changed
	  TYPE: A # Supports either A, AAA or CNAME
	  TTL: 1
          # Uncomment the following 3 vars if you want to change the Proxy, TTL and Type (usually it's set once, and no need to change) 
          #UPDATE_TYPE: True
          #UPDATE_PROXY: True
          #UPDATE_TTL: True
    restart: "unless-stopped"

volumes:
  app-data:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: /volume1/docker/cloudflare-dns-updater

⁠Example domains.json file

{
    "zones": [
        {
            "id": "$CF_ZONE_ID",
            "domains":
            [
                {
                    "name": "sub1.example.com"
                },
                {
                    "name": "sub2.example.com"
                },
                {
                    "name": "example.com"
                }
            ]
        }
    ]
}

⁠Tutorials

⁠🔑 How to create and get an API Token from Cloudflare
  1. Log in to your Cloudflare account.
  2. Navigate to your profile settings by clicking on your account icon in the top right corner of the dashboard.
  3. Navigate to the “API Tokens” link from the left side menu.
  4. Click the Create Token under User API Tokens.
  5. Under Templates use the Edit zone DNS template.
  6. Rename the token to your liking and change the Zone resources to Include All zones.
  7. Continue to summary and then Create token
  8. Copy the token shown. This is your API_TOKEN.
  9. ⚠️ THIS TOKEN WILL BE SHOWN ONLY ONCE. DO NOT FORGET TO SAVE IT! ⚠️
⁠🌍 Obtaining the Zone ID

To obtain the Zone ID for your domain from Cloudflare, follow these steps:

  1. Log in to your Cloudflare account.
  2. Select the domain you want to manage from the list of domains in your dashboard.
  3. On the domain’s overview page, you will find the Zone ID displayed in the right-hand sidebar under the “API” section. This is your Zone ID for your domain.
  4. [OPTIONAL] If you have multiple zones, repeat steps 1-3 for each zone.

⁠Issues

For any issues, open a ticket at https://github.com/SpasovskiFilip/dns-updater⁠

Tag summary

Content type

Image

Digest

sha256:3a618ca3a…

Size

20.8 MB

Last updated

about 1 year ago

docker pull spaskifilip/cloudflare-dns-updater