← Kartar.Net

Excellent script for automatically updating root hints file for Bind


I was going to write a script to automatically update the root hints files on my Bind servers. Then I found this excellent script - you will need to modify it to suit your own environment: #!/bin/sh # # Update the nameserver cache information file once per month. # This is run automatically by a cron entry. # # Original by Al Longyear # Updated for BIND 8 by Nicolai Langfeldt # Miscelanious error-conditions reported by David A. Ranch # Ping test suggested by Martin Foster # named up-test suggested by Erik Bryer. # ( echo “To: root “ echo “From: system “ # Is named up? Check the status of named. case rndc status 2>&1 in refused) echo “named is DOWN. root.hints was NOT updated” echo exit 0 ;; esac PATH=/sbin:/usr/sbin:/bin:/usr/bin: export PATH # NOTE: /var/named/master must be writable only by trusted users or this script # will cause root compromise/denial of service opportunities. cd /var/named/master 2>/dev/null || { echo “Subject: Cannot cd to /var/named/master, error $?” echo echo “The subject says it all” exit 1 } # Are we online? Ping a server at your ISP case ping -qnc 1 somehost.net 2>&1 in ‘100% packet loss’) echo “Subject: db.cache NOT updated. The network is DOWN.” echo echo “The subject says it all” exit 1 ;; esac dig @e.root-servers.net . ns >db.cache.new 2> errors case cat db.cache.new in NOERROR) # It worked :;; *) echo “Subject: The db.cache file update has FAILED.” echo echo “The db.cache update has failed” echo “This is the dig output reported:” echo cat db.cache.new errors exit 1 ;; esac echo “Subject: The db.cache file has been updated” echo echo “The db.cache file has been updated to contain the following information:” echo cat db.cache.new chown named.named db.cache.new chmod 444 db.cache.new rm -f db.cache.old errors mv db.cache db.cache.old mv db.cache.new db.cache rndc reload echo echo “The nameserver has been restarted to ensure that the update is complete.” echo “The previous root.hints file is now called /var/named/master/db.cache.old.” ) 2>&1 | /usr/lib/sendmail -t exit 0

Tags: repo

blog comments powered by Disqus

Eurovision - like crack for sarcastics ---