{"id":22069376,"url":"https://github.com/glocktober/setmycfdns","last_synced_at":"2026-02-07T15:07:31.156Z","repository":{"id":57465946,"uuid":"458924091","full_name":"Glocktober/setmycfdns","owner":"Glocktober","description":"Update cloudflare DNS record based on retrieved public ip","archived":false,"fork":false,"pushed_at":"2024-12-26T03:24:08.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-26T09:45:54.393Z","etag":null,"topics":["cloudflare","dns","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Glocktober.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-13T20:31:29.000Z","updated_at":"2024-12-26T03:24:12.000Z","dependencies_parsed_at":"2022-09-19T08:31:26.918Z","dependency_job_id":null,"html_url":"https://github.com/Glocktober/setmycfdns","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glocktober%2Fsetmycfdns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glocktober%2Fsetmycfdns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glocktober%2Fsetmycfdns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Glocktober%2Fsetmycfdns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Glocktober","download_url":"https://codeload.github.com/Glocktober/setmycfdns/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236112925,"owners_count":19096851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudflare","dns","python"],"created_at":"2024-11-30T20:09:03.841Z","updated_at":"2025-10-11T16:31:33.551Z","avatar_url":"https://github.com/Glocktober.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## setmycfdns - DNS updates for Cloudflare\n\nThe scenerio exists where a servers public (external) IP address can change over time.  This is especially true with cloud computing.  \n\nAs instances are stopped or hibernated and then restarted - their public IPs change, leaving public DNS records out of date.\n\nThis program can be used to update CloudFlare zone records when a server reboots or returns from hibernation. This gives CloudFlare users the same benifit as a cloud-native DNS solutions.\n\n### Limitations\n`setmycfdns` will update ***existing*** DNS records - the records must ***already exist*** in your CloudFlare zone. \n\n`setmycfdns` doesn't create or remove records (well... look at the undocumented options --create-record and --delete-record)\n\nThis is by design to prevent things from going wrong.\n\n`setmycfdns` updates **A** and **AAAA** DNS records; other records are not supported.\n\n## setmycfdns Command Usage and Options\nAfter configuring `setmycfdns` is simple to use and in most instances does not require any special switchs.\n```bash\n % setmycfdns \n```\nThis will **automatically** find your public IP address and update the dns zone record based on the *fully qualifed domain name* (fqdn) of your computer.\n\nIn a more complex configuration you can use a different name or multiple ip address.\n```bash\n % setmycfdns --fqdn first.example.com\n % setmycfdns --fqdn second.example.com -ip 100.100.22.23\n```\nA list of all availabe options:\n```\n% setmycfdns --help\nusage: setmycfdns [-h] [-v] [-ip IP] [-fqdn FQDN] [-q] [-z ZONE] [-6]\n\nUpdate CloudFlare IP record\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -v, --version         show program's version number and exit\n  -ip IP, --ip IP       set specific IP address to use\n  -fqdn FQDN, --fqdn FQDN\n                        Fully Qualified Domain Name (rkmbp.sunyocc.edu)\n  -q, --query           Query only - no updates are made\n  -z ZONE, --zone ZONE  Cloudflare Zone to update (optional)\n  -6                    Update AAAA record (default is A record)\n\nsetmycfdns gunville 2024 v2\n\n#### Automatic IP detection:\n\nBy default `setmyip` automatically detects the public IP address by sending an HTTP request to [ipv4.icanhazip.com](http://ipv4.icanhazip.com). This site returns the IPv4 address of the sender.\n\nYou can optionally use a different site to autodetect the public ip by setting the environment variable `IPAPIURL` to that URL:\n```bash\n% IPAPIURL='http://api.ipify.org'\n% setmycfdns\n````\nYou can do the same for IPv6 using `IPV6APIURL`.\n\nWhen ipv6 is selected with the `-6` switch automatic detection uses the ipv6 stack.  [ipv6.icanhazip.com](http://ipv6.icanhazip.com).\n\nIf your host has multiple ip addresses or uses a proxy for web requests you will need to provide the ip address to use with the `--ip IP` command line switch.\n\n```bash\n% setmycfdns -ip 100.123.4.56\n% setmycfdns -6 -ip 2600:1f16:a44:1701:1be3:f8b7:aa51:410b \n```\n\n#### Automatic Hostname Determination:\n\nThe fqdn of the host is acquired with the Python `socket.gethostname()` function. (Several solutions were tried, none worked perfect, but this one seems to work best.)\n\nThere are some limitations to hostname determination:\n* Some systems are not configured to provide the fqdn (*web01.example.com*) and provide only the short hostname (*web01*). There is no elegant and simple solution that works on all platforms and configurations. \n\n* In some environments the hostname on the private side (e.g. web01.local) is not the same one used on the public side (web01.example.com).\n\n* Likewise, cloud VPCs by default provide hostnames in a similar fashion (e.g. *ip-172-31-84-22.ec2.internal*)\n\nIn these cases you will be required to provide the full fqdn with the `--fqdn FQDN` switch.\n```bash\n% setmycfdns --fqdn web01.example.com \n```\n\n#### CloudFlare Zone selection:\n\nThe cloudflare zone is selected from the FQDN, but can also explicity provided with the `--zone ZONE` switch.\n\nIf the `--zone` switch is used the the zone does not match the hostname determined above, the fqdn is constructed by appending the zone.\n```bash\n% hostname\nserver1\n% setmycfdns --fqdn server1.example.com        # server1.example.com\n% setmycfdns --fqdn server1 --zone example.com # server1.example.com\n% setmycfdns --zone eample.com                 # server1.example.com\n```\n\nThe above are identical. Note that the `fqdn` does not have to be 'fully qualified' when the `--zone` switch is used.\n\n#### IPv6 Support\n\nBoth ipv4 **A** and ipv6 **AAAA** DNS records are supported by `setmycfdns`.  To update ipv6 records the `-6` switch is used - and required.\n\n```bash\n% setmycfdns -6\n```\n\n# Installation and Configuration\n`setmycfdns` is easily installed using `pip`\n```bash\n% pip install setmycfdns\n```\n\n#### CloudFlare API Keys\n\nCloudFlare credentials (API keys) are required. You will need to generate these in your CloudFlare account.\n\n\u003c\u003c\u003c\u003c\u003c\u003c\u003c HEAD\nGenerally a `.cloudflare.cf` file in the users home directory or the current working directory, but there are several options. The format is dictated by the `python-cloudflare` API library and [details can be found here.](https://github.com/cloudflare/python-cloudflare/blob/master/README.md)\n=======\nGenerally a `.cloudflare.cf` file in the users home directory or the current working directory, but there are several options. The format is dictated by the `python-cloudflare` API library and [details can be found here.](https://github.com/cloudflare/python-cloudflare/blob/master/README.md)  These are a TOML formated file with a CloudFlare tier and values for email and api_key.\n\nAlternative to the `.cloudflare.cf' file you can pass credentials using the environment variables CLOUDFLARE_EMAIL and CLOUDFLARE_KEY.\n\u003e\u003e\u003e\u003e\u003e\u003e\u003e 543cb5ef539fa33c11afecc9fdf19a7dcd1b901c\n\n***Remember to always protect these API keys.***\n\n#### Configuring `setmycfdns` to Run On Reboots (optional)\n\nThe following `crontab` entry will run `setmycfdns` each time the server reboots. \n```\n@reboot /usr/local/bin/setmycfdns\n```\nThe actual path depends on where you install `setmycfdns`\n\n#### Configuring `setmycfdns` To Run Post Hibernation (optional)\nThis may differ some depending on the operating system. This example here works with RedHat flavors.\n* Create the following file in `/lib/systemd/system-sleep/`\n* Add these contents of the file \n* Set the file to be excutable\n\n```bash\n% sudo touch /lib/systemd/system-sleep/20_cfdns\n% sudo chomd +x /lib/systemd/system-sleep/20_cfdns\n% cat \u003e /lib/systemd/system-sleep/20_cfdns \u003c\u003cEOF\n#!/usr/bin/env bash\naction=\"$1/$2\"\ncase \"$action\" in\n   pre/hibernate)\n   ;;\n   post/hibernate)\n\t/usr/local/bin/setmycfdns\n   ;;\nesac\n\u003e\u003e\n```\nThe actual path depends on where you install `setmycfdns`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglocktober%2Fsetmycfdns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fglocktober%2Fsetmycfdns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fglocktober%2Fsetmycfdns/lists"}