Automated zone generation using cron

Refresher on FRED

Remember the prerequisites for creating objects in the Fred DB (from https://fred.nic.cz/page/2906/installation-ubuntu/ and https://fred.nic.cz/page/699/fred-client-how-to/

  1. Make sure you have an existing contact, or create one
  2. Make sure you have an NS-set, or create one, and associate it to the contact
  3. Once the above are fulfilled, you can create a domain, referencing the contact and NS-set

From the Ubuntu installation above, you remember running this command near the end:

genzone_client

... if you remember, this automatically generated (created and wrote the contents) all the zones to disk.

Let's create a place where we can export our zones:

cd
mkdir zones
cd zones
pwd

The 4 commands above make sure you that:

Once you've done this, let's run the genzone_client:

genzone_client

Then

ls -l

... you should see at list one file, for the zone of the domain for the TLD that was created when you installed FRED.

For example, you may see:

-rw-rw-r-- 1 sysadm sysadm 719 Jun  1 07:19 db.dk

Automate zone generation

Now, we would like to have the above "zone generation" take place automatically, so we don't need to remember to do it manually every time we make changes in the zone.

It turns out that the FRED packages have this already configured!

cat /etc/cron.d/pyfred-genzone 

You should see:

*/30 *  * * *   root    /usr/bin/genzone_client

Every 30 minutes of every hour, every day, every month, all weekdays, run the commands "/usr/bin/genzone_client"

By default, the zones are being written to the /root directory. You can go there and look:

cd /root
ls -l

Do you see any zone files ?

The details

Let's look at the format above, called a crontab:

Minute  Hour    Day-of-Month    Month   Day-of-Week     User    Command [params]

For example, if we wanted to say "hello" at 5 minute past the hour on every hour, Monday to Friday, we would write:

5   *   *   *   *   1-5     root    echo "hello"

This reads as:

At 5 minute past the hour, every hour, every day, every month, Mon-Fri, say hello (as the root user)

The crontab for pyfred-genzone can be modified, so instead of running every 30 minutes, we're going to make it run every 5 minutes.

sudo vi /etc/cron.d/pyfred-genzone

Modify the line

*/30 *  * * *   root    /usr/bin/genzone_client

And change '30' to '5'

*/5 *  * * *   root /usr/bin/genzone_client

The above reads as:

Every 5 minutes of every hour, every day, every month, all weekdays, run the commands "/usr/bin/genzone_client"

Once you've change the line, save the file and exit.

Now instead of waiting 5 minutes, let's start configure BIND!