2016.05.08 01:31 | Kurt Tomlinson
If you have any reason to want to connect to your Raspbery Pi when you're away from home, you're going to want a dynamic DNS address. A dynamic DNS address lets you use a constant address like raspberry.johnsmith.com instead of an ever-changing IP address. This is useful if you've set up a VPN server on your Raspberry Pi or just like to tinker over SSH while you're away.
This tutorial hinges on the assumption that you have a domain name registered with Google Domains. If you have a domain with another registrar, then you should either move your domains to Google, or find another tutorial for dynamic DNS on a Raspberry Pi.Update: Scroll down to the bottom to see the ddclient configuration to use with Cloudflare.
This tutorial lets you use a subdomain of one of your domains to point to your raspberry pi. After forwarding the correct ports from your router you your Raspberry Pi, you'd then be able to access your Raspberry Pi from anywhere in the world.
The first step is to go to the DNS records for the domain you want to use for your dynamic DNS address. There, scroll down to the Synthetic records section and add a Dynamic DNS entry. For me, my dynamic DNS entry is "raspi.kurttomlinson.com".
Next, expand the Dynamic DNS section of that web page and click "View credentials". This will show you a randomly generated username and password that you'll need later.
Next, ssh into your raspberry pi and install ddclient: sudo apt-get install ddclient. Once it's installed, a few prompts will pop up. It doesn't really matter what you enter into the prompts. The prompts are used to created a configuration file for you, but we're going to replace that configuration file anyway.
sudo apt-get install ddclient
To edit ddclient's configuration file, enter sudo nano /etc/ddclient.conf. Make the configuration file look like the image, but replace the username and password with the username and password you got from Google Domains earlier. Replace the last line with the dynamic domain you created earlier on Google Domains. Here's the content of the config file for your convenience:
sudo nano /etc/ddclient.conf
Finally, make sure that ddclient gets run at boot. You can add ddclient to your rc.local file to do this.
I recently started using Cloudflare for my DNS entries, so here's the ddclient configuration to use with them:
For the password, use your Global API key. It can be found in the profile section of your Cloudflare account. The 'zone' is the domain/site you have registered on Cloudflare. Note: that's not really my API key, so don't bother trying to use it.
You need to install a Perl module from CPAN for ddclient to work with Cloudflare:
sudo cpan install JSON::Any
You also need to create an A record with the subdomain you want to update with ddclient. ddclient only updates your DNS entries. It will not create a new entry for you.
Photo by The Preiser Project