<commit_before><!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cheap DynDNS Alternative | blog.kilian.io</title>
<link rel="stylesheet" href="http://blog.kilian.io//css/style.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css">


<section class="section">
  <div class="container">
    <nav class="nav">
      <div class="nav-left">
        <a class="nav-item" href="http://blog.kilian.io/"><h1 class="title is-4">blog.kilian.io</h1></a>
      </div>
      <div class="nav-right">
        <nav class="nav-item level is-mobile">
          
          <a class="level-item" href="https://github.com/kiliankoe">
            <span class="icon">
              <i class="fa fa-github"></i>
            </span>
          </a>
          
          <a class="level-item" href="https://twitter.com/kiliankoe">
            <span class="icon">
              <i class="fa fa-twitter"></i>
            </span>
          </a>
          
          <a class="level-item" href="/index.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>
          </a>
          
        </nav>
      </div>
    </nav>
  </div>
</section>

<section class="section">
  <div class="container">
    <h2 class="subtitle is-6">March 7, 2016</h2>
    <h1 class="title">Cheap DynDNS Alternative</h1>
    <div class="content">
      <p>Until recently I had the pleasure of living with a static IP. This made accessing my Raspberry PI from outside my home rather easy. I could just open the port on my router and hardcode the IP anywhere.</p>

<p>After moving though easy access like that unfortunately fell away. I looked into some services like DynDNS but found them cumbersome and hard to work with. A simple solution to this “problem” presented itself via CloudFlare. Why not just get my current IP every $TIME_INTERVAL or so and send that to CloudFlare via their API updating an existing DNS record.</p>

<p>Here’s a simple ruby script for just that.</p>

<script src="https://gist.github.com/kiliankoe/268c13efa87c510bf8ad.js"></script>

<p>The script relies on two things to work correctly:</p>

<ul>
<li>Make sure to set the record to be updated beforehand, this script will look at all records and update the IP of the correct one.</li>
<li>You need to pass a few environment variables as specified at the top of the script, namely <code>CLOUDFLARE_EMAIL</code>, <code>CLOUDFLARE_API_KEY</code>, <code>CLOUDFLARE_ZONE</code> and <code>CLOUDFLARE_RECORD_NAME</code>.</li>
</ul>

<p>Now just periodically run it via cron or however you like 🙂</p>

<p>Setting up the record beforehand also gives you the freedom of specifying if you want CloudFlare tunneling for the record or not. Whatever you set will not be changed by this script.</p>

<p><strong>UPDATE</strong>: Thanks to <a href="https://twitter.com/stefanmajewsky">@stefanmajewsky</a> <a href="https://github.com/jasontbradshaw/gandi-dyndns">here</a>’s a Python script for doing the same directly via Gandi.net. Awesome!</p>

    </div>
    <hr>
    <div class="comments">
      Comments for this post can be found on <a href="https://github.com/kiliankoe/blog/issues">GitHub</a>. If there's no issue for this post already, just go ahead and open one 👌
    </div>
  </div>
</section>


<section class="section">
  <div class="container has-text-centered">
    <p></p><commit_msg>rebuilding site Wed May 10 20:32:30 CEST 2017<commit_after><!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cheap DynDNS Alternative | blog.kilian.io</title>
<link rel="stylesheet" href="http://blog.kilian.io//css/style.css">
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/github.min.css">


<section class="section">
  <div class="container">
    <nav class="nav">
      <div class="nav-left">
        <a class="nav-item" href="http://blog.kilian.io/"><h1 class="title is-4">blog.kilian.io</h1></a>
      </div>
      <div class="nav-right">
        <nav class="nav-item level is-mobile">
          
          <a class="level-item" href="https://github.com/kiliankoe">
            <span class="icon">
              <i class="fa fa-github"></i>
            </span>
          </a>
          
          <a class="level-item" href="https://twitter.com/kiliankoe">
            <span class="icon">
              <i class="fa fa-twitter"></i>
            </span>
          </a>
          
          <a class="level-item" href="/index.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>
          </a>
          
        </nav>
      </div>
    </nav>
  </div>
</section>

<section class="section">
  <div class="container">
    <h2 class="subtitle is-6">March 7, 2016</h2>
    <h1 class="title">Cheap DynDNS Alternative</h1>
    <div class="content">
      <p>Until recently I had the pleasure of living with a static IP. This made accessing my Raspberry PI from outside my home rather easy. I could just open the port on my router and hardcode the IP anywhere.</p>

<p>After moving though easy access like that unfortunately fell away. I looked into some services like DynDNS but found them cumbersome and hard to work with. A simple solution to this “problem” presented itself via CloudFlare. Why not just get my current IP every $TIME_INTERVAL or so and send that to CloudFlare via their API updating an existing DNS record.</p>

<p>Here’s a simple ruby script for just that.</p>

<pre><code class="language-ruby">#! /usr/bin/env ruby

require 'net/http'
require 'cloudflare'

# Email used for login
CLOUDFLARE_EMAIL = ENV[&quot;CLOUDFLARE_EMAIL&quot;]

# API Key, can be found here =&gt; https://www.cloudflare.com/a/account/my-account
CLOUDFLARE_API_KEY = ENV[&quot;CLOUDFLARE_API_KEY&quot;]

# The zone (aka domain) this is for, e.g. 'example.com'
CLOUDFLARE_ZONE = ENV[&quot;CLOUDFLARE_ZONE&quot;]

# The specific record name to edit, e.g. 'record.example.com'
CLOUDFLARE_RECORD_NAME = ENV[&quot;CLOUDFLARE_RECORD_NAME&quot;]

def get_ip
  Net::HTTP.get(URI.parse('http://canihazip.com/s'))
end

def update_cloudflare(ip)
  cf = CloudFlare::connection(CLOUDFLARE_API_KEY, CLOUDFLARE_EMAIL)
  begin
    rec_id = ''
    records = cf.rec_load_all(CLOUDFLARE_ZONE)
    records['response']['recs']['objs'].each do |record|
      if record['name'] == CLOUDFLARE_RECORD_NAME
        rec_id = record['rec_id']
        break
      end
    end
    # Sending '1' for the TTL = 'automatic' meaning approx. 300 (5 minutes)
    cf.rec_edit(CLOUDFLARE_ZONE, 'A', rec_id, CLOUDFLARE_RECORD_NAME, ip, 1)
  rescue =&gt; e
    puts e.message
  else
    puts &quot;Successfully updated A record for #{CLOUDFLARE_RECORD_NAME} to #{ip}&quot;
  end
end

update_cloudflare(get_ip)
</code></pre>

<p>The script relies on two things to work correctly:</p>

<ul>
<li>Make sure to set the record to be updated beforehand, this script will look at all records and update the IP of the correct one.</li>
<li>You need to pass a few environment variables as specified at the top of the script, namely <code>CLOUDFLARE_EMAIL</code>, <code>CLOUDFLARE_API_KEY</code>, <code>CLOUDFLARE_ZONE</code> and <code>CLOUDFLARE_RECORD_NAME</code>.</li>
</ul>

<p>Now just periodically run it via cron or however you like 🙂</p>

<p>Setting up the record beforehand also gives you the freedom of specifying if you want CloudFlare tunneling for the record or not. Whatever you set will not be changed by this script.</p>

<p><strong>UPDATE</strong>: Thanks to <a href="https://twitter.com/stefanmajewsky">@stefanmajewsky</a> <a href="https://github.com/jasontbradshaw/gandi-dyndns">here</a>’s a Python script for doing the same directly via Gandi.net. Awesome!</p>

    </div>
    <hr>
    <div class="comments">
      Comments for this post can be found on <a href="https://github.com/kiliankoe/blog/issues">GitHub</a>. If there's no issue for this post already, just go ahead and open one 👌
    </div>
  </div>
</section>


<section class="section">
  <div class="container has-text-centered">
    <p></p>
{'fraction_non_alphanumeric': 0.14144893111638954, 'fraction_numerical': 0.00843230403800475, 'mean_word_length': 3.322895277207392, 'pattern_counts': {'":': 0, '<': 201, '<?xml version=': 0, '>': 201, 'https://': 12, 'lorem ipsum': 0, 'www.': 1, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '962911', 'n_tokens_mistral': 2850, 'n_tokens_neox': 2758, 'n_words': 827}