Making your Domain Name from GoDaddy work as DDNS using RaspberryPi

RaspberryPi is a credit card sized powerhouse capable of hosting a web server, doing home automation and much more. With everything going online these days and skyrocketing bills of server hosting providers, the only way to get your presence online is by hosting your website yourself. Sure, that sounds simple but how do I get www.somewebsite.com to use my ever changing Dynamic IP Address assigned to my home router by my ISP? In comes, DDNS to save the day!

Alright! But what the hell is DDNS? Good question. A simple Google Search for What is DDNS would result in the following:

Dynamic DNS (DDNS or DynDNS) is a method of automatically updating a name server in the Domain Name System (DNS), often in real time, with the active DDNSconfiguration of its configured hostnames, addresses or other information. The term is used to describe two different concepts.

OK what?!

Right! That’s too much tech jargon to take in for one day. Let’s simplify it.

DDNS is way of making sure that whenever your ISP provides you with a new IP, you update the pointer of www.somewebsite.com to use that IP Address instead of the old one, thus making sure your site is always online.

That made sense right! Its simple and with a bit of code magic we can make sure this happens automatically every few minutes. So let’s jump right in!

Prerequisites:

  1. Your purchased domain name from GoDaddy (we’ll use www.somewebsite.com for this post)
  2. A RaspberryPi (any model as long as its working)
  3. Python Packages installed (godaddypy and requests)
  4. Port forwarding on your router port 80 to your RaspberryPi (Google for Port forwarding web server in router)
  5. Presence of mind

Once you have this all, we’re good to go!

Let’s start by logging into the Developer panel of GoDaddy to generate some authentication tokens for our script. Open https://developer.godaddy.com/keys/ in your browser. It looks something like this:

Developer Portal GoDaddy

Scroll down to find the Production section, and click the Big Plus Sign on its right. You should see a popup dialog like below:

godaddy-2

Pay heed to the big yellow info box in the dialog above, copy the Key and Secret and store it somewhere safe, if lost, you’ll have to generate a new pair again. With that done, you can log out from GoDaddy.

Now SSH into your RaspberryPi and let’s start coding. The python script is just 20 lines of code, here’s the code for it:

The script basically performs the following tasks:

  1. Using http://jsonip.com it gets your current public IP
  2. It logs in to your GoDaddy Account using the API Keys and gets the current A record for somewebsite.com
  3. It compares if your current public IP has changed from the record
    • If not, it just prints it out on the console and exits
    • If the IP has changed, it updates the A record against the domain name

Save the python script above to any location you want, preferably the home folder of the user pi:

Now edit your crontab using the command “crontab -e” and paste the following line:

What this will do is, every 5 minutes run the python script and append the output of each run to /home/pi/updater.log

That’s it!

Now even if your Public IP gets changed, within 5 mins the new IP will get updated against the A record of your domain name.

Now its easy to run a website off your RaspberryPi in a cost effective manner without having to pay hundreds of dollars for server hosting and static IPs.

Let me know your experience in the comment section below. Feedback, suggestions are always welcome!

4 thoughts on “Making your Domain Name from GoDaddy work as DDNS using RaspberryPi

  1. Hi,

    I cant get your code to work 🙁
    when i run it (with my key & secret)

    I get:
    Traceback (most recent call last):
    File “/home/pi/Python-Source/python/dnsUP.py”, line 14, in
    current_record = client.get_records(‘tonaud.co.uk’, record_type=’A’)[0]
    File “/usr/local/lib/python2.7/dist-packages/godaddypy/client.py”, line 180, in get_records
    data = self._get_json_from_response(url)
    File “/usr/local/lib/python2.7/dist-packages/godaddypy/client.py”, line 56, in _get_json_from_response
    return self._request_submit(requests.get, url=url, json=json, **kwargs).json()
    File “/usr/local/lib/python2.7/dist-packages/godaddypy/client.py”, line 82, in _request_submit
    self._validate_response_success(resp)
    File “/usr/local/lib/python2.7/dist-packages/godaddypy/client.py”, line 98, in _validate_response_success
    raise BadResponse(response.json())
    BadResponse: Response Data: {u’message’: u’Unauthorized : Could not authenticate API key/secret’, u’code’: u’UNABLE_TO_AUTHENTICATE’}

    1. Hi Tony,
      Looks like the key you generated does not work. UNABLE_TO_AUTHENTICATE means the API validation failed. Please check API docs from godaddy for this.

  2. Hello, thank you flr this tutorial! Having some problemssss. I bought a static IP from my ISP and a domain from go daddy. I have done port forwarding to 80 and 22 for SSH. I added my static IP to record A. But I am still unable to access it from outside my local network. Any ideas? Thank you in advance!!

    1. Hi Ren,
      Welcome. If you have a static IP then you don’t need to use this script, since your IP is constant.
      Check if your router has any firewall rules that may be blocking port 80.

Leave a Reply

Your email address will not be published. Required fields are marked *

*