Custom Domain, DDNS, and Raspberry PI

Using a custom domain with a dynamic IP

Custom Domain, DDNS, and Raspberry PI

Inspired by this article:

Your own DNS

You need to get bind running on your rasp pi. Lots of tutorials about this in the ether (install bind9).

Change the /etc/bind/named.conf.local file

zone "" {  
	type master;  
    file "/home/pi/homedns/";

You need to define a zone file:

$TTL 60S
@ IN SOA (  
	2017081402 ; serial  
    8H ; refresh  
    2H ; retry  
    4W ; expire  
    60S ; minimum


www                 A
homepage  CNAME       www

You need to have two nameserver domains with your ddns provider (eg: no-ip, duckdns), in the example above and

Start bind

sudo systemctl start bind9

Check it is resolving locally

dig -tns @localhost

The NS authority section should say “”

Configure your domain name provider

Set your nameserver for your custom domain in your domain provider (such as 123-reg) to point to the two name servers defined in your ddns (eg, and

For example in you would go to the manage nameserver section to replace the 123 ns1/ns2 server urls with your new ddns ones. You can then use the dig command to check:

dig -tns

It should respond with your ddns nameservers (note: the change in your domain provider can take a while).



The IP address should be of your dynamic ISP.

NOTE: You should have a script to keep the ip in your DDNS provider in step with the dynamic IP provided by your ISP.

Zone IP Changes

The next part is to then also change the zone file for the domain as well whenever your ISP changes the IP.

This is a perl script to change the zone IP (based on Ian Atkinsons’ perl script):

You can use crontab to check the IP every so often and then update the zone file using the script.  Like so (assuming the script above is named and is in your homedns directory):

*/6 * * * * ~/homedns/ >/dev/null 2>&1

Test Your Server

You can easily run a server on your local machine (such as nginx), even easier if you have docker.

On more thing you need to do is to open up your router to allow the outside world to connect to the Rasp Pi (your machine) to the specific port running your server.

You also need to allow the router to connect to your Bind DNS server (port 53 for both TCP and UDP)

You won’t be able to call your custom domain inside your home network (unless to add the domain to /etc/hosts). However an easy way is to turn off the Wifi on your mobile and use the data network to test.

Mail Forwarding

If you need to forward mail to say then you can add the following mx records in your file. Here the mail server is from 123-reg.

@       MX 1
@       MX 2

And you can check the MX records with

dig mx

You should see an answer section like so


~ Voila ~