{"id":482,"date":"2013-08-25T14:21:25","date_gmt":"2013-08-25T12:21:25","guid":{"rendered":"http:\/\/bergs.biz\/blog\/?p=482"},"modified":"2013-08-25T14:21:25","modified_gmt":"2013-08-25T12:21:25","slug":"how-to-roll-your-own-dyndns","status":"publish","type":"post","link":"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/","title":{"rendered":"How to roll your own DynDNS&#8230;"},"content":{"rendered":"<p>I didn&#8217;t want to rely upon services like <code>DynDNS.org<\/code> (which obviously was a smart decision since they now pretty much closed their free service) so I rolled my own&#8230;<\/p>\n<p>What you need is the following:<\/p>\n<ol>\n<li>Host your domain yourself using the popular nameserver &#8220;Bind.&#8221;<\/li>\n<li>Host a small CGI script that will tell you your external IP (or use one of the many free services available that do the same).<\/li>\n<li>Run a machine within your LAN 24&#215;7 which can detect changes of your external IP and update your hostname accordingly.<\/li>\n<\/ol>\n<h2>Step 1: Setup Bind for Dynamic DNS Update<\/h2>\n<p>to do<\/p>\n<h2>Step 2: CGI Script<\/h2>\n<p>The CGI script that needs to be deployed somewhere in the Internet to tell you your external IP is very simple and tiny and looks like this:<\/p>\n<pre>#!\/bin\/bash\r\necho \"Content-type: text\/plain\"\r\necho \"\"\r\necho \"$REMOTE_ADDR\"<\/pre>\n<h2>Step 3: External IP Probe<\/h2>\n<p>Here&#8217;s the script that needs to run periodically on a machine (I use Ubuntu server) within your LAN (or on your Internet gateway, although if you have the means to run stuff on your gateway you could employ a more elegant, &#8220;proper&#8221; solution):<\/p>\n<pre>#!\/bin\/bash\r\nlockfile=\"\/run\/extip\"\r\nlockfile-check $lockfile\r\nif [ $? -eq 0 ]; then\r\n\u00a0\u00a0 \u00a0echo \"Locked, bailing out...\"\r\n\u00a0\u00a0 \u00a0exit 1\r\nfi\r\n\r\nlockfile-create $lockfile\r\nfilename=\"\/var\/lib\/extip.txt\"\r\nlogfile=\"\/var\/log\/extip.log\"\r\nkeyfile=\"\/root\/var\/lib\/dyndns\/Kmyhost.dyn.example.org.+163+56719.key\"\r\ncur_ip=`curl -s http:\/\/example.org\/cgi-bin\/myip.sh`\r\nprev_ip=`cat $filename`\r\nif [ $cur_ip != $prev_ip ]; then\r\n\u00a0\u00a0 \u00a0echo \"`date --rfc-3339=seconds` IP changed, old IP: $prev_ip, new IP: $cur_ip\" &gt;&gt;$logfile\r\n\u00a0\u00a0 \u00a0echo \"$cur_ip\" &gt;$filename\r\n\u00a0\u00a0 \u00a0# Wait 5 sec to complete, force kill if nsupdate not done after 10 sec\r\n\u00a0\u00a0 \u00a0timeout -k 10s 5s nsupdate -k $keyfile -v&lt;&lt;EOF\r\nserver example.org\r\nzone dyn.example.org.\r\nupdate delete myhost.dyn.example.org. A\r\nupdate add myhost.dyn.example.org. 60 A $cur_ip\r\nsend\r\nEOF\r\nfi\r\nlockfile-remove $lockfile<\/pre>\n<p>The above script &#8212; even though it&#8217;s pretty small &#8212; is not a quick&#8217;n&#8217;dirty hack, but even employs some sanity checks:<\/p>\n<ul>\n<li>It makes sure that only <em>one<\/em> instance is running at any time, and<\/li>\n<li>it uses the <code>timeout<\/code> command from the Linux <code>coreutils<\/code> package to enforce that the <code>nsupdate<\/code> command will be terminated if it takes longer than 10 s (e. g. due to network issues).<\/li>\n<\/ul>\n<p>I run the above script once a minute as follows:<\/p>\n<pre># cat \/etc\/cron.d\/extip \r\n* * * * * root \/usr\/local\/bin\/pubextip.sh<\/pre>\n<p>That&#8217;s it!<\/p>\n<p>Let me know what you think. Suggestions how to improve things are, as always, very welcome!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I didn&#8217;t want to rely upon services like DynDNS.org (which obviously was a smart decision since they now pretty much closed their free service) so I rolled my own&#8230; What you need is the following: Host your domain yourself using the popular nameserver &#8220;Bind.&#8221; Host a small CGI script that will tell you your external [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[81,93],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-linux-computers","tag-dynamic-dns","tag-dyndns"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to roll your own DynDNS... - Ralf&#039;s Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to roll your own DynDNS... - Ralf&#039;s Blog\" \/>\n<meta property=\"og:description\" content=\"I didn&#8217;t want to rely upon services like DynDNS.org (which obviously was a smart decision since they now pretty much closed their free service) so I rolled my own&#8230; What you need is the following: Host your domain yourself using the popular nameserver &#8220;Bind.&#8221; Host a small CGI script that will tell you your external [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/\" \/>\n<meta property=\"og:site_name\" content=\"Ralf&#039;s Blog\" \/>\n<meta property=\"article:published_time\" content=\"2013-08-25T12:21:25+00:00\" \/>\n<meta name=\"author\" content=\"Ralf Bergs\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ralfbergs\" \/>\n<meta name=\"twitter:site\" content=\"@ralfbergs\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ralf Bergs\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/2013\\\/08\\\/25\\\/how-to-roll-your-own-dyndns\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/2013\\\/08\\\/25\\\/how-to-roll-your-own-dyndns\\\/\"},\"author\":{\"name\":\"Ralf Bergs\",\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/#\\\/schema\\\/person\\\/354e37390b493c875f972bd313d29201\"},\"headline\":\"How to roll your own DynDNS&#8230;\",\"datePublished\":\"2013-08-25T12:21:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/2013\\\/08\\\/25\\\/how-to-roll-your-own-dyndns\\\/\"},\"wordCount\":276,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/#\\\/schema\\\/person\\\/354e37390b493c875f972bd313d29201\"},\"keywords\":[\"dynamic DNS\",\"DynDNS\"],\"articleSection\":[\"Linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/bergs.biz\\\/blog\\\/2013\\\/08\\\/25\\\/how-to-roll-your-own-dyndns\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/2013\\\/08\\\/25\\\/how-to-roll-your-own-dyndns\\\/\",\"url\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/2013\\\/08\\\/25\\\/how-to-roll-your-own-dyndns\\\/\",\"name\":\"How to roll your own DynDNS... - Ralf&#039;s Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/#website\"},\"datePublished\":\"2013-08-25T12:21:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/2013\\\/08\\\/25\\\/how-to-roll-your-own-dyndns\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/bergs.biz\\\/blog\\\/2013\\\/08\\\/25\\\/how-to-roll-your-own-dyndns\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/2013\\\/08\\\/25\\\/how-to-roll-your-own-dyndns\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to roll your own DynDNS&#8230;\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/\",\"name\":\"Ralf's Blog\",\"description\":\"Just another WordPress weblog\",\"publisher\":{\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/#\\\/schema\\\/person\\\/354e37390b493c875f972bd313d29201\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/#\\\/schema\\\/person\\\/354e37390b493c875f972bd313d29201\",\"name\":\"Ralf Bergs\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/Ralf-Tower-2026-1024x1024.jpg\",\"url\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/Ralf-Tower-2026-1024x1024.jpg\",\"contentUrl\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/Ralf-Tower-2026-1024x1024.jpg\",\"width\":1024,\"height\":1024,\"caption\":\"Ralf Bergs\"},\"logo\":{\"@id\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/Ralf-Tower-2026-1024x1024.jpg\"},\"description\":\"Geek, computer guy, licensed and certified electrical and computer engineer, husband, best daddy.\",\"sameAs\":[\"https:\\\/\\\/bergs.biz\\\/\",\"https:\\\/\\\/linkedin.com\\\/in\\\/ralfbergs\\\/\",\"https:\\\/\\\/x.com\\\/ralfbergs\"],\"url\":\"https:\\\/\\\/bergs.biz\\\/blog\\\/author\\\/rabe\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to roll your own DynDNS... - Ralf&#039;s Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/","og_locale":"en_US","og_type":"article","og_title":"How to roll your own DynDNS... - Ralf&#039;s Blog","og_description":"I didn&#8217;t want to rely upon services like DynDNS.org (which obviously was a smart decision since they now pretty much closed their free service) so I rolled my own&#8230; What you need is the following: Host your domain yourself using the popular nameserver &#8220;Bind.&#8221; Host a small CGI script that will tell you your external [&hellip;]","og_url":"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/","og_site_name":"Ralf&#039;s Blog","article_published_time":"2013-08-25T12:21:25+00:00","author":"Ralf Bergs","twitter_card":"summary_large_image","twitter_creator":"@ralfbergs","twitter_site":"@ralfbergs","twitter_misc":{"Written by":"Ralf Bergs","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/#article","isPartOf":{"@id":"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/"},"author":{"name":"Ralf Bergs","@id":"https:\/\/bergs.biz\/blog\/#\/schema\/person\/354e37390b493c875f972bd313d29201"},"headline":"How to roll your own DynDNS&#8230;","datePublished":"2013-08-25T12:21:25+00:00","mainEntityOfPage":{"@id":"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/"},"wordCount":276,"commentCount":0,"publisher":{"@id":"https:\/\/bergs.biz\/blog\/#\/schema\/person\/354e37390b493c875f972bd313d29201"},"keywords":["dynamic DNS","DynDNS"],"articleSection":["Linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/","url":"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/","name":"How to roll your own DynDNS... - Ralf&#039;s Blog","isPartOf":{"@id":"https:\/\/bergs.biz\/blog\/#website"},"datePublished":"2013-08-25T12:21:25+00:00","breadcrumb":{"@id":"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/bergs.biz\/blog\/2013\/08\/25\/how-to-roll-your-own-dyndns\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bergs.biz\/blog\/"},{"@type":"ListItem","position":2,"name":"How to roll your own DynDNS&#8230;"}]},{"@type":"WebSite","@id":"https:\/\/bergs.biz\/blog\/#website","url":"https:\/\/bergs.biz\/blog\/","name":"Ralf's Blog","description":"Just another WordPress weblog","publisher":{"@id":"https:\/\/bergs.biz\/blog\/#\/schema\/person\/354e37390b493c875f972bd313d29201"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bergs.biz\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/bergs.biz\/blog\/#\/schema\/person\/354e37390b493c875f972bd313d29201","name":"Ralf Bergs","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bergs.biz\/blog\/wp-content\/uploads\/2026\/04\/Ralf-Tower-2026-1024x1024.jpg","url":"https:\/\/bergs.biz\/blog\/wp-content\/uploads\/2026\/04\/Ralf-Tower-2026-1024x1024.jpg","contentUrl":"https:\/\/bergs.biz\/blog\/wp-content\/uploads\/2026\/04\/Ralf-Tower-2026-1024x1024.jpg","width":1024,"height":1024,"caption":"Ralf Bergs"},"logo":{"@id":"https:\/\/bergs.biz\/blog\/wp-content\/uploads\/2026\/04\/Ralf-Tower-2026-1024x1024.jpg"},"description":"Geek, computer guy, licensed and certified electrical and computer engineer, husband, best daddy.","sameAs":["https:\/\/bergs.biz\/","https:\/\/linkedin.com\/in\/ralfbergs\/","https:\/\/x.com\/ralfbergs"],"url":"https:\/\/bergs.biz\/blog\/author\/rabe\/"}]}},"_links":{"self":[{"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/posts\/482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/comments?post=482"}],"version-history":[{"count":4,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/posts\/482\/revisions"}],"predecessor-version":[{"id":486,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/posts\/482\/revisions\/486"}],"wp:attachment":[{"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/media?parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/categories?post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bergs.biz\/blog\/wp-json\/wp\/v2\/tags?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}