:: Exporting NicTool to BIND

2 min read

:: What is
+ NicTool
NicTool is a free DNS management suite that takes all the headaches out of managing DNS. It includes an attractive web interface for users, admins, and clients to access and update their DNS zone data as well as a rich API for provisioning systems to interact with. All zone data is stored in MySQL and is extracted by export scripts to the DNS server of choice (tinydns, BIND, PowerDNS). :: NicTool

BIND is the most widely used DNS software on the Internet. On Unix-like operating systems it is the de facto standard. :: wikipedia
:: Installing Requirement
+ Installing Bind on Linux Debian

aptitude install bind9

+ Installing NicTool
:: Create script for Export to BIND

mkdir /exportscript
cd /exportscript/
vi export_bind.php

add these line:


/* nictool bind export script  - created by Mihai Secasiu - //patchlog.com */

/* Version 1.3
1. SOA records were inverted
2. in-addr.arpa zones were not being generated correctly
3. Fixed a major bug where an empty zones.conf file was generated if the export script was unable to connect to MySQL (very bad as it means no zone data loaded or served!!)


$zones_dir="data/"; // directory used for storing the zone files, the script will delete the zone that are set as deleted from this folder.
$zone_template="{ZONE_NAME}.zone";  //  template used for zone filename. {ZONE_NAME} will be replaced by script with the domain name
$conf_file="data/zones.conf"; // file where the script will write the zone entries. The script will truncate the file on open


	die("cannot open configuration file: $conf_filen");

function get_ns($nsid)
	global $nameservers;
	if(isset($nameservers[$nsid]))return $nameservers[$nsid];
	$sql="SELECT name,ttl,description FROM nt_nameserver where nt_nameserver_id=".intval($nsid)." and deleted!='1'";
		die("query: $sql: failed with error: ".mysql_error()."n");
	return $nameservers[$nsid];

	die("cound not connect to the database servern");

mysql_select_db($db_name, $dbl) or die("Could not select database: $db_namen");

		$nsq="AND (ns0 = $ns OR ns1 = $ns OR ns2 = $ns OR ns3 = $ns OR ns4 = $ns OR ns5 = $ns
			OR ns6 = $ns OR ns7 = $ns OR ns8 = $ns OR ns9 = $ns) ";
		die("nameserver id invalid or nameserver deletedn");


$sql="SELECT * FROM nt_zone $nsq";
	die("query: $sql: failed with error: ".mysql_error()."n");

			echo "Deleted zone file for zone ${z['zone']}n";

	$nst=""; // nameserver text
	$fns=""; // first nameserver for SOA record
		if($z['ns'.$i] && ($ns=get_ns($z['ns'.$i])) ){
			$nst.="@	${ns['ttl']} IN NS	${ns['name']} ; ${ns['description']}n";

	echo "Generating zone file for domain: ".$z['zone']." -";
	$t="; ${z['description']}
$ttl ${z['ttl']}
@	IN	SOA	$fns	${z['mailaddr']} (
			${z['minimum']} )

	$sql="SELECT * FROM nt_zone_record where nt_zone_id=".$z['nt_zone_id']. " and deleted!='1'";

		die("query: $sql: failed with error: ".mysql_error()."n");
		$t.="${r['name']} ${r['ttl']} IN ${r['type']}";
			$t.="	${r['address']}";
			$t.="	"${r['address']}"";
			$t.="	${r['weight']} ${r['address']}";
			$t.="	${r['priority']} ${r['weight']} ${r['other']} ${r['address']}";
		$t.="	; ${r['description']}n";
		die("error writing to file: $fnn");
zone "${z['zone']}" IN {
	type master;
	file "$fn";
	allow-update {none; };
	notify no;

		die("error writing to zones configuration file: $conf_filen");

	echo " file generated OKn";


echo "Successfully exported $c domains. Exiting..n";

:: Setup crontab for exporting zone file
+ Create zonecopy.sh

cd /exportscript/
vi zonecopy.sh

add these line:


# exporting
cd /exportscript/
/usr/bin/php export_bind.php

# copy zone file

# local server
scp data/* /var/cache/bind/data

# remotely
scp data/* [email protected]:/var/cache/bind/data
scp data/* [email protected]:/var/cache/bind/data

# reload
# local
killall -HUP named

# remotely
ssh [email protected] killall -HUP named
ssh [email protected] killall -HUP named

sleep 5

+ Setup crontab

crontab -e

setup like this:

*/5 * * * * /bin/sh /exportscript/zonecopy.sh >/dev/null 1>/dev/null

:: Create sub folder in the directory that your script is located in called "data"

cd /exportscript
mkdir data
chown bind.bind data

:: Add zones.conf to named.conf

vi /etc/bind/named.conf

add this line:

include "/exportscript/data/zones.conf";

:: Setup working directory and users
+ Create directory for exporting

cd /var/cache/bind
mkdir data
chown bind.bind data

+ Modify shell on bind users

vi /etc/passwd

change on this line, like:


:: Testing
Add some DNS zone on NicToolClient, and testing your zone record useing dig, nslookup, host or other domain tool checker.
:: Links
+ Google
+ LinuxPower

How to fix problem with the editor ‘vi’

:: git error with vi error: There was a problem with the editor 'vi'   :: how to fix the problem 0. check path...
10 sec read

Apache :: MP4 Streaming

:: How to Enable mp4 Streaming in Apache + Installing mod h624 streaming wget //h264.code-shop.com/download/apache_mod_h264_streaming-2.2.7.tar.gz tar -xzf apache_mod_h264_streaming-2.2.7.tar.gz cd mod_h264_streaming-2.2.7/ ./configure --with-apxs=`which apxs2` make...
18 sec read

Apache :: Flash / FLV Streaming

:: How to Configure Apache for FLV Streaming + Installing mod_flvx wget //people.apache.org/~pquerna/modules/mod_flvx.c which apxs /usr/bin/apxs /usr/bin/apxs -cia mod_flvx.c + setup mod_flvx in http.conf...
15 sec read

Leave a Reply

Your email address will not be published. Required fields are marked *