Setting up Dynamic DNS for your Nextcloud server
Updated: Apr 19
You'll need to have completed the first tutorial in this series before completing this guide:
In this guide, we'll help you setup DDNS for your Nextcloud server. This can be for two reasons; firstly, if you're using a consumer based Internet service provider, it's likely that your IP address changes regularly. This causes a fundamental problem when trying to access your Nextcloud from outside of your home, as you never know what your IP address is. Secondly, even if you do have a static IP address from your ISP, it's hard to remember that address all of the time, and can be laborious typing it in.
DDNS addresses both of these issues by killing two birds with one stone. By running a very lightweight client on a device within in your home (in this case, your Raspberry Pi), the client can constantly communicate your IP address to a designated location (DDNS provider). When you create a free account with a DDNS provider, you will need to register a hostname that's linked to your account. This hostname is the address in which you'll use to access your Nextcloud.
So for example, let's say that your external IP address this morning at 7AM was 22.214.171.124, and then at 2PM it changed to 126.96.36.199. Because your Pi is constantly connected to your router, it is able, with the help of a DDNS client to communicate these IP address changes to your DDNS provider. So let's say the hostname that you've registered is joescloud.dynamic-dns.net. At 7AM, joescloud.dynamic-dns.net would resolve to 188.8.131.52. At 2PM the same address would resolve to 184.108.40.206.
For this guide, we'll be using DDclient for the DDNS client, and we'll be using ChangeIP for the DDNS provider.
Let's get started...
Setup your DDNS account and hostname
As we mentioned earlier, we'll be using ChangeIP as it's free, has a good choice of hostname domains and most importantly, doesn't require you to login to your account every 30 days to keep your account active. So without further ado, click here to setup your account with ChangeIP.
Once there, select DNS from the top menu and then select Dynamic DNS:
Now click the Claim free dynamic DNS button:
Now you'll get to choose your hostname. This is the address at which you'll access your Nexcloud from outside your home:
Continue through the checkout/registration processes until your account is setup. Note: although you checkout, the service is free, you don't need to enter credit card information etc.
Alternatively, you can also choose to acquire your own domain from less than $10 per year (this would mean having something trendier like joescloud.com instead of joescloud.dynamic-dns.net) To do so, go to “Domain – Register a new domain“. Choose at the top level which domain you prefer (prices will vary) and the domain name to buy.
Installing and configuring DDclient
Now that your domain name is setup, let's install DDclient to ensure your hostname is constantly updated with your current IP address. Run this command on your Raspberry Pi:
$ sudo apt-get install ddclient
During the installation, a configuration wizard will appear. This will prompt you for several pieces of information. Do not worry about these prompts, input any information you like, as we'll be manually inputting the relevant information into a text file later. Also, you may receive an error regarding passwords not matching, just ignore these. Once DDclient has finished installing, enter the following command to edit the DDclient configuration file:
$ sudo nano /etc/ddclient.conf
Now copy the text below and change the relevant information to match your own. I've bolded the information that you need to change. Save the file by pressing <Ctrl> + x followed by y and then press <Enter>:
# Configuration file for ddclient generated by debconf # # /etc/ddclient.conf protocol=changeip ssl=yes use=web, web=ip.changeip.com server=nic.changeip.com/nic/update email@example.com password='YOURPASS' joescloud.dynamic-dns.net
Next, run the following two commands to start the service and to enable to service to run at boot:
$ sudo systemctl start ddclient.service
$ sudo systemctl enable ddclient.service
You can check whether the service is working by running the following command. You should hopefully see a success entry at the bottom.:
$ sudo service ddclient status
You can also check on the ChangeIP site. If you login, go to the Services dropdown menu and select DNS Manager, then click View recent DNS updates. If everything has worked, you should see an entry like the below:
Well done, you've now configured DDNS and DDclient. You'll need to follow our post here to configure Port Forwarding and enabling HTTPS for your Nextcloud server.
So you've setup DDNS on your Raspberry Pi, however you need to setup Port Forwarding on your router to direct incoming traffic to your Raspberry Pi. If you just type your DDNS hostname into a browser outside your home, your router won't know where to send the information. (You probably have many devices attached to your home router, including wireless devices; such as phones, laptops, etc.) So we need to tell your router, that when you input joescloud.dynamic-dns.net into your browser while outside the home, it knows to send and receive data to and from your Raspberry Pi.
We'll cover Port Forwarding in our next post: Enable SSL on your Nextcloud server