Creating custom dynamic dns by yourself

If you have your own domain, you are running bind and you don't want to use various DDNS providers like http://dyndns.org or http://no-ip.com for your home network, you can use your bind and a subdomain to point a dns entry to your public IP at home. I'm using nsupdate, cron and a simple bash script to do this.

This solution is for IPv4 only, but with minor changes you will get it running with IPv6 (do you need DDNS on IPv6?)

Requirements

  • nsupdate - usually from bind, named, bind-tools or named-tools package
  • curl
  • cron

Create the keys

dnssec-keygen -a HMAC-MD5 -b 512 -n USER yourhost.

You've got two files, with private and public keys.

Configuring DNS client

Create /etc/bind/keys and copy your key files, set the permissions

chmod 700 /etc/bind/keys
chmod 600 /etc/bind/keys/*

Configuring DNS server

Put your public key to /etc/bind/keys.conf with following syntax(put only the key from the file, not the whole DNS record):

key yourhostkey {
    algorithm HMAC-MD5;
    secret "<<your public key here>>";
};

Include it in named.conf

include "/etc/bind/keys.conf"

Set the right permissions:

chown root:named keys.conf 
chmod 640 keys.conf 

You have two possibilities now, to allow all updates in the zone or to restrict it to specified entry.

Allow all updates, put this to your zone configuration

allow-update {
       key yourhostkey;
};

Only one specified entry

update-policy {
       grant   yourhostkey name yourhost. A;
};

If' you are using allow-query statements to block some queries, don't forget to add “key yourhostkey;” to allow-query. Otherwise named will block update queries.

Optional: create own PHP script

If you want to use your own public IP detection, create the following script and place it on your web server:

detectip.php
<?php
echo getenv ("REMOTE_ADDR");
?>

Creating the script

Download the script and open it for editing. Configure the settings on the top

#some settings
DNS_RECORDS="yourhost.yourdomain.com yourdomain.com someotherrecord.yourdomain.com"
DNS_SERVER=yourdnsserver.com
DNS_ZONE=yourdomain.com
DNS_KEY_FILE="Kyourhostfile.private"
DNS_TTL="60"
STATE_FILE="/var/tmp/custom_ddns_last_ip"
#IP_DETECT_URL="http://checkip.dyndns.org/"
IP_DETECT_URL="http://automation.whatismyip.com/n09230945.asp"
PRE_UPDATE_CMD=""

Change DNS_KEY_FILE to the path of your private key. You can change IP_DETECT_URL to your custom url. If you need to run something before updating, place the command in PRE_UPDATE_CMD

Create a cron job to run this script, that's all!

See too

Discussion

Enter your comment. Wiki syntax is allowed:
If you can't read the letters on the image, download this .wav file to get them read to you.