{"id":238,"date":"2013-06-03T20:51:53","date_gmt":"2013-06-03T19:51:53","guid":{"rendered":"http:\/\/www.psinke.nl\/wordpress\/?p=238"},"modified":"2015-12-07T12:23:57","modified_gmt":"2015-12-07T11:23:57","slug":"create-a-diy-dynamic-dns-service","status":"publish","type":"post","link":"https:\/\/www.psinke.nl\/blog\/create-a-diy-dynamic-dns-service\/","title":{"rendered":"Create a DIY dynamic DNS service, for free"},"content":{"rendered":"<div class=\"afa2b3b851443650502c43e85c746c1f\" data-index=\"1\" style=\"float: none; margin:0px;\">\n<script type=\"text\/javascript\"><!--\r\ngoogle_ad_client = \"ca-pub-4223201538046844\";\r\n\/* standaardblok *\/\r\ngoogle_ad_slot = \"9522527129\";\r\ngoogle_ad_width = 320;\r\ngoogle_ad_height = 50;\r\n\/\/-->\r\n<\/script>\r\n<script type=\"text\/javascript\"\r\nsrc=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\r\n<\/script>\n<\/div>\n<p>I&#8217;m one of the unlucky people with a provider who doesn&#8217;t provide a static IP address. One solution would be to subscribe to a Dynamic DNS (or DDNS) service like <a title=\"DynDNS\" href=\"http:\/\/dyn.com\/dns\/\" target=\"_blank\">DynDNS<\/a>. Those services are not free (anymore), and although the subscription price is not too steep, it does not justify for the limited use I have.<\/p>\n<p>A little scripting provided a solution which works for me too. I previously ran this on\u00a0a Mac,\u00a0but since I have a Raspberry Pi running anyway, the script is now scheduled on the Raspberry Pi with the Raspbian OS \u00a0installed.<\/p>\n<p>First, I need to obtain my external IP address. There are plenty of free services. I found a little script that does the job for me:<\/p>\n<pre>curl -L -s --max-time 10 http:\/\/checkip.dyndns.org | \r\n      egrep -o -m 1 '([[:digit:]]{1,3}\\.){3}[[:digit:]]{1,3}'<\/pre>\n<p>It fetches the webpage from the DynDNS site and strips out \u00a0the IP address using a regular expression.<\/p>\n<p>I created a quick and dirty shell script that creates a file that contains some simple HTML with a redirect to my public IP. The generated file is then uploaded to my hosting provider:<\/p>\n<pre>printf \"&lt;html&gt;&lt;head&gt;&lt;meta HTTP-EQUIV=\\\"REFRESH\\\" content=\\\"0; url=http:\/\/\" &gt; redirect.html\r\ncurl -L -s --max-time 10 http:\/\/checkip.dyndns.org | egrep -o -m 1 '([[:digit:]]{1,3}\\.){3}[[:digit:]]{1,3}' &gt;&gt;redirect.html\r\nprintf \"\\\"&gt;&lt;\/head&gt;&lt;body&gt;Redirecting ...&lt;\/body&gt;&lt;\/html&gt;\" &gt;&gt; redirect.html\r\ncurl -u user:password -T redirect.html ftp:\/\/ftp.mysite:21<\/pre>\n<p>Not the most elegant code, but it works. I can run this manually or schedule it with <em>launchd<\/em>,\u00a0<em>cron<\/em> or something similar. If necessary you can even manually create the HTML file and upload it yourself from time to time.<\/p>\n<p>The final step I took was make sure the page redirects me to a webserver running locally in a virtual machine. I set one up in Virtualbox, using a Bridged Network so it acts as a full network citizen in my local network. Creating a port forwarding entry in my router ensures that all incoming requests on port 80 are redirected to port 7780 on the IP address of the virtual machine.<\/p>\n<p>And so I&#8217;m done. Opening the page on my hosted site automatically redirects me to my local web server. At no cost and hardly any coding at all!<\/p>\n<h2>Addition January 1st., 2014:<\/h2>\n<p>I&#8217;ve found another trick that might not always work, but it rules out the need for an external service to display your external IP address.<\/p>\n<p>The following line returns your external IP adres in OS X:<\/p>\n<p>curl ifconfig.me<\/p>\n<p>The script then becomes as simple as:<\/p>\n<pre>printf \"&lt;html&gt;&lt;head&gt;&lt;meta HTTP-EQUIV=\\\"REFRESH\\\" content=\\\"0; url=http:\/\/\" &gt; redirect.html\r\ncurl ifconfig.me\u00a0&gt;&gt;redirect.html\r\nprintf \"\\\"&gt;&lt;\/head&gt;&lt;body&gt;Redirecting ...&lt;\/body&gt;&lt;\/html&gt;\" &gt;&gt; redirect.html\r\ncurl -u user:password -T redirect.html ftp:\/\/ftp.mysite:21<\/pre>\n<pre><\/pre>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m one of the unlucky people with a provider who doesn&#8217;t provide a static IP address. One solution would be to subscribe to a Dynamic DNS (or DDNS) service like DynDNS. Those services are not free (anymore), and although the subscription price is not too steep, it does not justify for the limited use I&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,121],"tags":[249,285,252,254,247,250,246,286,102,13,396,244,395,394,397,253,251,198,248,207],"class_list":["post-238","post","type-post","status-publish","format-standard","hentry","category-web-and-beyond","category-tips-and-tricks","tag-bridged-network","tag-cron","tag-curl","tag-ddns","tag-dynamic-dns","tag-dynamic-ip","tag-dyndns","tag-launchd","tag-linux","tag-os-x","tag-pi","tag-port-forwarding","tag-raspberry","tag-raspberry-pi","tag-raspbian","tag-script","tag-static-ip","tag-unix","tag-virtual-machine","tag-virtualbox"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.psinke.nl\/blog\/wp-json\/wp\/v2\/posts\/238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.psinke.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.psinke.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.psinke.nl\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.psinke.nl\/blog\/wp-json\/wp\/v2\/comments?post=238"}],"version-history":[{"count":2,"href":"https:\/\/www.psinke.nl\/blog\/wp-json\/wp\/v2\/posts\/238\/revisions"}],"predecessor-version":[{"id":479,"href":"https:\/\/www.psinke.nl\/blog\/wp-json\/wp\/v2\/posts\/238\/revisions\/479"}],"wp:attachment":[{"href":"https:\/\/www.psinke.nl\/blog\/wp-json\/wp\/v2\/media?parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.psinke.nl\/blog\/wp-json\/wp\/v2\/categories?post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.psinke.nl\/blog\/wp-json\/wp\/v2\/tags?post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}