Sunday, 2010-01-03 17:03 MST

Automating Updating Files

I run my own DNS servers at home. I have to, or I'd never find some of the computers on my home network. Running your own DNS server means occasionally updating the list of root servers.

DNS works by querying a name server. If the name server is authoritative for the zone you are interested in, it responds and that's that. If it isn't, it has to query the authoritative server and relay the response to the inquiring client. In order to do the latter, it has to locate the authoritative server. It does that by querying one or more "root" name servers. Root servers come and go, which means you need to fetch a list of them from time to time. Monthly is probably overkill.

Being the lazy bum that I am, I wanted to automate doing that.

It's easy enough to set up a monthly fetch of the file, using crontab and wget. Here's how I did it: I added these lines to my /etc/crontab:

# minute, hour, day of the month, month, and weekday
# 0-59,   0-23, 1-31,             1-12,  0-7 (0 & 7 = Sunday)
  23      0     3                 *      *   root cd /var/named/etc && wget -N ftp://ftp.internic.net/domain/named.root

The first two lines are comments, but they help me set up the timing correctly for entries. As you can see, the third line is triggered at the 23rd minute of the 0th hour (0:23) on the third day of every month. If you think monthly is too often, give it a comma delimited list, e.g. 3,6,9,12 for quarterly.

The next column indicates the user to run as. This column is unique to /etc/crontab; don't put it into other crontab files.

The last column is the command that is executed. I run named in a chrooted jail. The first thing, then, is to cd into the jail's /etc directory. If and only if that is successful, we get the file. The -N switch tells wget to test whether the file is newer than our copy, and only fetch it if it is newer.

That's it.

There are other files one could grab from time to time. OpenAFS users may want to grab the list of public AFS servers and snoop around in, say, NASA's AFS servers. Like so:

0  0    * *  0 root cd /etc/openafs/ && wget -N http://grand.central.org/dl/cellservdb/CellServDB

I will leave as an exercise for the student when and how often that runs.


Posted by Charles Curley | Permanent link | File under: linux