{"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\/no\/blog\/administrirovanie\/svoj-dynamic-dns-s-pomoshhyu-cloudflare","title":{"rendered":"Din dynamiske DNS med CloudFlare","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<h3>Forord<\/h3>\n<p>\n<img decoding=\"async\" alt=\"Din dynamiske DNS med CloudFlare\" src=\"\/wp-content\/uploads\/2019\/10\/d1405e23e86048a05e6707bb5e9e215f.jpg\" style=\"display:block;margin: 0 auto;\" \/> For personal needs, I set up VSphere at home, where I run a virtual router and an Ubuntu server as a media server along with a bunch of other goodies, and this server needs to be accessible from the Internet. But the problem is that my provider charges for static IPs, which I could always find more useful applications for. So I used the combination of ddclient + cloudflare. <\/p>\n<p>Everything was fine until ddclient stopped working. After poking around, I realized it was time for hacks and workarounds, as I was spending too much time searching for the problem. In the end, it all turned into a small daemon that just works, and that\u2019s all I needed. <br \/>\nFor those interested \u2013 welcome under the cut.<br \/>\n<noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<h3>Tools used and how \"it\" works<\/h3>\n<p>\nSo the first thing I did was check the cloudflare site for everything I needed to know about <noindex><a rel=\"nofollow\" href=\"https:\/\/api.cloudflare.com\/\">API<\/a><\/noindex>. I had already started to implement everything in Python (after getting acquainted with Python, I increasingly use it for simple tasks or when I need to quickly create a prototype), when suddenly I stumbled upon a nearly complete implementation.<br \/>\nOverall, the base was taken from the 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 support for 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 retrieves a list of zones from the configuration file and loops through them<\/li>\n<li>In each zone, the script loops through each A or AAAA DNS record and checks the Public IP against the record<\/li>\n<li>If the IP is different \u2014 it changes it; if not, it skips the loop iteration and moves to the next <\/li>\n<li>Sleeps for the time specified in the config<\/li>\n<\/ol>\n<p><\/p>\n<h3>Installasjon og konfigurasjon<\/h3>\n<p>\nProbably it would be possible to create a .deb package, but I'm not strong in that, and it\u2019s not that complicated anyway.<br \/>\nI described the process quite thoroughly 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 \u2013 install them (in 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>Dette er en vanlig JSON-fil, med enkle innstillinger \u2013 jeg har spesifikt beskrevet to forskjellige soner som eksempel.\n<\/li>\n<\/ol>\n<p><\/p>\n<h4>Hva skjuler seg bak installat\u00f8rene?<\/h4>\n<p>\ninstall.sh for Linux:<\/p>\n<ol>\n<li>En bruker opprettes for \u00e5 kj\u00f8re demonen, uten opprettelse av hjemmekatalog og mulighet for innlogging.\n<pre><code class=\"plaintext\">sudo useradd -r -s \/bin\/false zen-cf-ddns<\/code><\/pre>\n<p>\n<\/li>\n<li>En fil opprettes for \u00e5 skrive logger til \/var\/log\/<\/li>\n<li>Vi gj\u00f8r den nylig opprettede brukeren til eier av loggfila<\/li>\n<li>Filene kopieres til sine plasser (konfigurasjon til \/etc, kj\u00f8rbar fil til \/usr\/bin, tjenestefil til \/lib\/systemd\/system)<\/li>\n<li>Tjenesten aktiveres<\/li>\n<\/ol>\n<p>\nwindows_install.bat for Windows:<\/p>\n<ol>\n<li>Kopierer den kj\u00f8rbare filen og konfigurasjonsfilen til den angitte brukermappen<\/li>\n<li>Oppretter en oppgave i planleggeren for \u00e5 kj\u00f8re skriptet ved systemoppstart<br \/>\n<code>schtasks \/create \/tn \"CloudFlare Update IP\" \/tr \"%newLocation%\" \/sc onstart<\/code>\n<\/li>\n<\/ol>\n<p>\nEtter endring av konfigurasjonen m\u00e5 skriptet startes p\u00e5 nytt, i Linux er alt enkelt og kjent:<\/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 m\u00e5 prosessen pythonw drepes og skriptet startes p\u00e5 nytt (jeg er veldig lat til \u00e5 skrive en tjeneste for Windows i C#):<\/p>\n<pre><code class=\"plaintext\">taskkill \/im pythonw.exe<\/code><\/pre>\n<p>\nDermed er installasjonen og konfigurasjonen fullf\u00f8rt, bruk den med glede.<\/p>\n<p>For de som \u00f8nsker \u00e5 se ikke den peneste Python-koden, her er den <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/DzenDyn\/zen-cf-ddns\">repository p\u00e5 GitHub<\/a><\/noindex>.<\/p>\n<p>MIT-lisens, s\u00e5 gj\u00f8r hva du vil med dette.<\/p>\n<p>P.S.: Jeg forst\u00e5r at det ble litt kl\u00f8nete, men det l\u00f8ser oppgaven min perfekt.<\/p>\n<p>UPD: 11.10.2019 17:37<br \/>\nJeg har funnet ett problem til, og om noen kan foresl\u00e5 hvordan det kan l\u00f8ses \u2013 vil jeg v\u00e6re sv\u00e6rt takknemlig.<br \/>\nProblemet er at hvis man installerer avhengigheter uten sudo python -m pip install -r &#8230;, s\u00e5 vil ikke modulene v\u00e6re synlige for tjeneste-brukeren, og jeg \u00f8nsker ikke \u00e5 tvinge brukerne til \u00e5 installere moduler med sudo, det er heller ikke riktig.<br \/>\nHvordan kan man gj\u00f8re det riktig, slik at det er pent?<br \/>\nUPD: 11.10.2019 19:16 Problemet er l\u00f8st ved bruk av venv.<br \/>\nDet ble gjort flere endringer. En ny utgivelse vil komme om dager.<br \/>\n<br \/>Kilde: <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.5 - 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\/no\/blog\/administrirovanie\/svoj-dynamic-dns-s-pomoshhyu-cloudflare\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.5\" \/>\n\t\t<meta property=\"og:locale\" content=\"nn_NO\" \/>\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\/no\/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\udd47Min egen dynamiske DNS med CloudFlare | ProHoster","description":"Forord Jeg satte opp dette for personlig bruk hjemme.","canonical_url":"https:\/\/prohoster.info\/no\/blog\/administrirovanie\/svoj-dynamic-dns-s-pomoshhyu-cloudflare","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"nn_NO","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\/no\/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\/no\/wp-json\/wp\/v2\/posts\/38840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/no\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/no\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/no\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/no\/wp-json\/wp\/v2\/comments?post=38840"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/no\/wp-json\/wp\/v2\/posts\/38840\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/no\/wp-json\/wp\/v2\/media\/29132"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/no\/wp-json\/wp\/v2\/media?parent=38840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/no\/wp-json\/wp\/v2\/categories?post=38840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/no\/wp-json\/wp\/v2\/tags?post=38840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}