{"id":38840,"date":"2019-10-31T22:26:17","date_gmt":"2019-10-31T19:26:17","guid":{"rendered":"https:\/\/prohoster.info\/blog\/svoj-dynamic-dns-s-pomoshhyu-cloudflare\/"},"modified":"2019-10-31T22:26:17","modified_gmt":"2019-10-31T19:26:17","slug":"svoj-dynamic-dns-s-pomoshhyu-cloudflare","status":"publish","type":"post","link":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/svoj-dynamic-dns-s-pomoshhyu-cloudflare","title":{"rendered":"Your dynamic DNS with CloudFlare","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<h3>Preface<\/h3>\n<p>\n<img decoding=\"async\" alt=\"Your dynamic DNS with CloudFlare\" src=\"\/wp-content\/uploads\/2019\/10\/d1405e23e86048a05e6707bb5e9e215f.jpg\" style=\"display:block;margin: 0 auto;\" \/> For personal use at home, I set up VSphere, on which I run a virtual router and an Ubuntu server as a media server, along with a bunch of other nice features, and this server needs to be accessible from the Internet. However, the problem is that my provider charges for static IPs, which can always be better utilized. Therefore, I used the ddclient + cloudflare combination. <\/p>\n<p>Everything was fine until ddclient stopped working. After digging into it a bit, I realized it was time for some hacks and workarounds since too much time was being spent finding the problem. In the end, it all resulted in a small daemon that just works, and that's all I needed. <br \/>\nFor anyone interested, welcome under the cut.<br \/>\n<noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<h3>Tools used and how \"this\" works<\/h3>\n<p>\nSo first of all, I learned everything needed on the cloudflare website about <noindex><a rel=\"nofollow\" href=\"https:\/\/api.cloudflare.com\/\">API<\/a><\/noindex>. I was already set to implement everything in Python (after getting to know Python, I increasingly use it for simple tasks or when I need to quickly make a prototype) when I suddenly stumbled upon a nearly ready implementation.<br \/>\nIn general, the basis was taken from a wrapper <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/cloudflare\/python-cloudflare\">python-cloudflare<\/a><\/noindex>.<\/p>\n<p>I took one of the examples for updating DNS and added the use of a configuration file and the ability to update multiple A records within a zone, and of course, an unlimited number of zones.<\/p>\n<p>The logic is as follows:<\/p>\n<ol>\n<li>The script reads the list of zones from the configuration file and iterates through them in a loop.<\/li>\n<li>In each zone, the script loops through each DNS A or AAAA record and compares the Public IP with the record.<\/li>\n<li>If the IP differs, it changes it; if not, it skips the iteration and moves on to the next one. <\/li>\n<li>It sleeps for the time specified in the config.<\/li>\n<\/ol>\n<p><\/p>\n<h3>Installation and setup<\/h3>\n<p>\nIt might be possible to make a .deb package, but I'm not strong in that, and it's not too complicated.<br \/>\nI described the process in detail in the README.md on <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/DzenDyn\/zen-cf-ddns\">the repository page.<\/a><\/noindex>.<\/p>\n<p>But just in case, I will describe it in general terms in Russian:<\/p>\n<ol>\n<li>Make sure you have python3 and python3-pip installed; if not, install them (on Windows, python3-pip is installed with Python).<\/li>\n<li>Clone or download the repository.<\/li>\n<li>Install the required dependencies.\n<pre><code class=\"plaintext\">python3 -m pip install -r requirements.txt<\/code><\/pre>\n<p>\n<\/li>\n<li>Run the installation script.<br \/>\nFor Linux:<\/p>\n<pre><code class=\"plaintext\">chmod +x install.sh\nsudo .\/install.sh<\/code><\/pre>\n<p>\nFor Windows: windows_install.bat\n<\/li>\n<li>Edit the configuration file.<br \/>\nFor Linux:<\/p>\n<pre><code class=\"plaintext\">sudoedit \/etc\/zen-cf-ddns.conf<\/code><\/pre>\n<p>\nFor Windows:<\/p>\n<p>Open the zen-cf-ddns.conf file in the folder where you installed the script.<\/p>\n<p>This is a regular JSON file; the settings are not complicated \u2013 I specifically described two different zones in it as an example.\n<\/li>\n<\/ol>\n<p><\/p>\n<h4>What lies behind the installers?<\/h4>\n<p>\ninstall.sh for Linux:<\/p>\n<ol>\n<li>A user is created to run the daemon, without creating a home directory and login capabilities.\n<pre><code class=\"plaintext\">sudo useradd -r -s \/bin\/false zen-cf-ddns<\/code><\/pre>\n<p>\n<\/li>\n<li>A file is created for logging in \/var\/log\/<\/li>\n<li>We make the recently created user the owner of the log file<\/li>\n<li>Files are copied to their respective places (config in \/etc, executable file in \/usr\/bin, service file in \/lib\/systemd\/system)<\/li>\n<li>The service is activated<\/li>\n<\/ol>\n<p>\nwindows_install.bat for Windows:<\/p>\n<ol>\n<li>Copies the executable file and the configuration file to the folder specified by the user<\/li>\n<li>Creates a task in the scheduler to run the script at system startup<br \/>\n<code>schtasks \/create \/tn \"CloudFlare Update IP\" \/tr \"%newLocation%\" \/sc onstart<\/code>\n<\/li>\n<\/ol>\n<p>\nAfter changing the config, the script needs to be restarted; in Linux, this is straightforward and familiar:<\/p>\n<pre><code class=\"plaintext\">sudo service zen-cf-ddns start\nsudo service zen-cf-ddns stop\nsudo service zen-cf-ddns restart\nsudo service zen-cf-ddns status\n<\/code><\/pre>\n<p>\nfor Windows, you will have to kill the pythonw process and restart the script (I\u2019m too lazy to write a service for Windows in C#):<\/p>\n<pre><code class=\"plaintext\">taskkill \/im pythonw.exe<\/code><\/pre>\n<p>\nThis concludes the installation and setup; enjoy using it.<\/p>\n<p>For those who want to see not the prettiest Python code, here it is <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/DzenDyn\/zen-cf-ddns\">repository on GitHub<\/a><\/noindex>.<\/p>\n<p>MIT License, so feel free to do what you want with it.<\/p>\n<p>P.S.: I understand it turned out a bit of a hack, but it fulfills its task with flying colors.<\/p>\n<p>UPD: 10\/11\/2019 5:37 PM<br \/>\nI found one more problem, and if anyone can suggest how to solve it\u2014I would be very grateful.<br \/>\nThe problem is that if dependencies are installed without using sudo python -m pip install -r ..., the modules won't be visible from the service user's perspective, and I wouldn't want to force users to install modules with sudo, as that's not correct.<br \/>\nHow can I do it correctly so that it looks nice?<br \/>\nUPD: 10\/11\/2019 7:16 PM The problem was resolved using venv.<br \/>\nThere were several changes. A new release will be coming soon.<br \/>\n<br \/>Source: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/471102\/\">habr.com<\/a><\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435 \u0414\u043b\u044f \u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0443\u0436\u0434 \u0434\u043e\u043c\u0430 \u043f\u043e\u0434\u043d\u044f\u043b VSphere, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u0440\u0443\u0447\u0443 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0440\u0448\u0440\u0443\u0442\u0438\u0437\u0430\u0442\u043e\u0440 \u0438 Ubuntu \u0441\u0435\u0440\u0432\u0435\u0440 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0435\u0434\u0438\u0430-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u0435\u0449\u0435 \u043a\u0443\u0447\u0438 \u0432\u0441\u044f\u043a\u0438\u0445 \u0432\u043a\u0443\u0441\u043d\u044f\u0448\u0435\u043a, \u0438 \u044d\u0442\u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0438\u0437 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442. \u041d\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u043e\u0439 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u0434\u0430\u0435\u0442 \u0441\u0442\u0430\u0442\u0438\u043a\u0443 \u0437\u0430 \u0434\u0435\u043d\u044c\u0433\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0441\u0432\u044f\u0437\u043a\u043e\u0439 ddclient + [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":29132,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-38840","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.2 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435 \u0414\u043b\u044f \u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0443\u0436\u0434 \u0434\u043e\u043c\u0430 \u043f\u043e\u0434\u043d\u044f\u043b.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/svoj-dynamic-dns-s-pomoshhyu-cloudflare\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.2\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0421\u0432\u043e\u0439 dynamic DNS \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e CloudFlare | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435 \u0414\u043b\u044f \u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0443\u0436\u0434 \u0434\u043e\u043c\u0430 \u043f\u043e\u0434\u043d\u044f\u043b.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/svoj-dynamic-dns-s-pomoshhyu-cloudflare\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-10-31T19:26:17+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-10-31T19:26:17+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Your own dynamic DNS with CloudFlare | ProHoster","description":"Preface I set it up for personal use at home.","canonical_url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/svoj-dynamic-dns-s-pomoshhyu-cloudflare","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0421\u0432\u043e\u0439 dynamic DNS \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e CloudFlare | ProHoster","og:description":"\u041f\u0440\u0435\u0434\u0438\u0441\u043b\u043e\u0432\u0438\u0435 \u0414\u043b\u044f \u043b\u0438\u0447\u043d\u044b\u0445 \u043d\u0443\u0436\u0434 \u0434\u043e\u043c\u0430 \u043f\u043e\u0434\u043d\u044f\u043b.","og:url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/svoj-dynamic-dns-s-pomoshhyu-cloudflare","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2019-10-31T19:26:17+00:00","article:modified_time":"2019-10-31T19:26:17+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"38840","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":"2026-01-23 23:37:19","breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-03-01 01:01:36","updated":"2026-01-23 23:37:19","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/38840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/comments?post=38840"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/38840\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media\/29132"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media?parent=38840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/categories?post=38840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/tags?post=38840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}